Skip to content

Commit

Permalink
Merge pull request #174 from Visionaid-International-Ltd/memory
Browse files Browse the repository at this point in the history
Some minor reductions in memory allocations
  • Loading branch information
ironfede authored Oct 3, 2024
2 parents 81c8928 + 138280a commit 00f260c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
3 changes: 1 addition & 2 deletions sources/OpenMcdf/CompoundFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,6 @@ List<Sector> result
break;

Sector ms = new Sector(Sector.MINISECTOR_SIZE, sourceStream);
byte[] temp = new byte[Sector.MINISECTOR_SIZE];

ms.Id = nextSecID;
ms.Type = SectorType.Mini;
Expand Down Expand Up @@ -2630,7 +2629,7 @@ private static void DoCompression(CFStorage currSrcStorage, CFStorage currDstSto
{
CFStorage itemAsStorage = item as CFStorage;
CFStorage strg = currDstStorage.AddStorage(itemAsStorage.Name);
strg.CLSID = new Guid(itemAsStorage.CLSID.ToByteArray());
strg.CLSID = itemAsStorage.CLSID;
DoCompression(itemAsStorage, strg); // recursion, one level deeper
}
};
Expand Down
8 changes: 1 addition & 7 deletions sources/OpenMcdf/DirectoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,20 +437,14 @@ public override string ToString()
public void AssignValueTo(RedBlackTree.IRBNode other)
{
DirectoryEntry d = other as DirectoryEntry;

d.SetEntryName(GetEntryName());

d.CreationDate = new byte[CreationDate.Length];
CreationDate.CopyTo(d.CreationDate, 0);

d.ModifyDate = new byte[ModifyDate.Length];
ModifyDate.CopyTo(d.ModifyDate, 0);

d.Size = Size;
d.StartSect = StartSect;
d.StateBits = StateBits;
d.StgType = StgType;
d.storageCLSID = new Guid(storageCLSID.ToByteArray());
d.storageCLSID = storageCLSID;
d.Child = Child;
}

Expand Down
8 changes: 5 additions & 3 deletions sources/OpenMcdf/Sector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ public byte[] GetData()

public void ZeroData()
{
data = new byte[Size];
if (data is null)
data = new byte[Size];
else
Array.Clear(data, 0, data.Length);
DirtyFlag = true;
}

public void InitFATData()
{
data = new byte[Size];

data ??= new byte[Size];
for (int i = 0; i < Size; i++)
data[i] = 0xFF;

Expand Down

0 comments on commit 00f260c

Please sign in to comment.