Skip to content

Commit

Permalink
DFLogBuffer: move to longs
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Feb 22, 2024
1 parent af5a687 commit 76e91a7
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions ExtLibs/Utilities/DFLogBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Newtonsoft.Json;

namespace MissionPlanner.Utilities
Expand All @@ -21,23 +22,23 @@ public class DFLogBuffer : IEnumerable<String>, IDisposable
public DFLog dflog { get; }

Stream basestream;
private int _count;
List<uint> linestartoffset = new List<uint>();
private long _count;
List<long> linestartoffset = new List<long>();

/// <summary>
/// Type and offsets
/// </summary>
List<uint>[] messageindex = new List<uint>[256];
List<long>[] messageindex = new List<long>[256];
/// <summary>
/// Type and line numbers
/// </summary>
List<uint>[] messageindexline = new List<uint>[256];
List<long>[] messageindexline = new List<long>[256];

bool binary = false;

object locker = new object();

int indexcachelineno = -1;
long indexcachelineno = -1;
String currentindexcache = null;

public DFLogBuffer(string filename) : this(File.Open(filename,FileMode.Open,FileAccess.Read,FileShare.Read))
Expand All @@ -49,8 +50,8 @@ public DFLogBuffer(Stream instream)
dflog = new DFLog(this);
for (int a = 0; a < messageindex.Length; a++)
{
messageindex[a] = new List<uint>();
messageindexline[a] = new List<uint>();
messageindex[a] = new List<long>();
messageindexline[a] = new List<long>();
}

if (instream.CanSeek)
Expand Down Expand Up @@ -90,7 +91,7 @@ void setlinecount()

byte[] buffer = new byte[1024*1024];

var lineCount = 0;
var lineCount = 0l;

if (binary)
{
Expand All @@ -103,10 +104,10 @@ void setlinecount()
continue;

byte type = ans.Item1;
messageindex[type].Add((uint)(ans.Item2));
messageindexline[type].Add((uint) lineCount);
messageindex[type].Add(ans.Item2);
messageindexline[type].Add(lineCount);

linestartoffset.Add((uint)(ans.Item2));
linestartoffset.Add(ans.Item2);
lineCount++;

if (lineCount % 1000000 == 0)
Expand Down Expand Up @@ -359,6 +360,9 @@ public DFLog.DFItem this[long indexin]
{
get
{
if (indexin > int.MaxValue)
throw new Exception("index too large");

var index = (int)indexin;

long startoffset = linestartoffset[index];
Expand Down Expand Up @@ -464,7 +468,7 @@ public void Clear()

public int Count
{
get { return _count; }
get { if (_count > int.MaxValue) Console.WriteLine("log line count is too large"); return (int)_count; }
}

public bool IsReadOnly
Expand Down Expand Up @@ -549,6 +553,8 @@ public bool IsReadOnly
progress = DateTime.Now.Second;
}
var ans = this[(long) l];
if (!instances.ContainsKey(ans.msgtype))
continue;
var inst = instances[ans.msgtype];
// instance was requested, and its not a match
//if (inst != "" && ans.instance != inst)
Expand Down Expand Up @@ -606,11 +612,6 @@ public List<string> SeenMessageTypes
}
}

public String ReadLine()
{
return this[indexcachelineno+1];
}

public Tuple<string,double> GetUnit(string type, string header)
{
var answer = UnitMultiList.Where(tuple => tuple.Item1 == type && tuple.Item2 == header);
Expand Down

0 comments on commit 76e91a7

Please sign in to comment.