Skip to content

Commit 00f260c

Browse files
authored
Merge pull request #174 from Visionaid-International-Ltd/memory
Some minor reductions in memory allocations
2 parents 81c8928 + 138280a commit 00f260c

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

sources/OpenMcdf/CompoundFile.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,6 @@ List<Sector> result
14181418
break;
14191419

14201420
Sector ms = new Sector(Sector.MINISECTOR_SIZE, sourceStream);
1421-
byte[] temp = new byte[Sector.MINISECTOR_SIZE];
14221421

14231422
ms.Id = nextSecID;
14241423
ms.Type = SectorType.Mini;
@@ -2630,7 +2629,7 @@ private static void DoCompression(CFStorage currSrcStorage, CFStorage currDstSto
26302629
{
26312630
CFStorage itemAsStorage = item as CFStorage;
26322631
CFStorage strg = currDstStorage.AddStorage(itemAsStorage.Name);
2633-
strg.CLSID = new Guid(itemAsStorage.CLSID.ToByteArray());
2632+
strg.CLSID = itemAsStorage.CLSID;
26342633
DoCompression(itemAsStorage, strg); // recursion, one level deeper
26352634
}
26362635
};

sources/OpenMcdf/DirectoryEntry.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,14 @@ public override string ToString()
437437
public void AssignValueTo(RedBlackTree.IRBNode other)
438438
{
439439
DirectoryEntry d = other as DirectoryEntry;
440-
441440
d.SetEntryName(GetEntryName());
442-
443-
d.CreationDate = new byte[CreationDate.Length];
444441
CreationDate.CopyTo(d.CreationDate, 0);
445-
446-
d.ModifyDate = new byte[ModifyDate.Length];
447442
ModifyDate.CopyTo(d.ModifyDate, 0);
448-
449443
d.Size = Size;
450444
d.StartSect = StartSect;
451445
d.StateBits = StateBits;
452446
d.StgType = StgType;
453-
d.storageCLSID = new Guid(storageCLSID.ToByteArray());
447+
d.storageCLSID = storageCLSID;
454448
d.Child = Child;
455449
}
456450

sources/OpenMcdf/Sector.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ public byte[] GetData()
9898

9999
public void ZeroData()
100100
{
101-
data = new byte[Size];
101+
if (data is null)
102+
data = new byte[Size];
103+
else
104+
Array.Clear(data, 0, data.Length);
102105
DirtyFlag = true;
103106
}
104107

105108
public void InitFATData()
106109
{
107-
data = new byte[Size];
108-
110+
data ??= new byte[Size];
109111
for (int i = 0; i < Size; i++)
110112
data[i] = 0xFF;
111113

0 commit comments

Comments
 (0)