Skip to content

Commit

Permalink
Apply code cleanup and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Nov 19, 2024
1 parent 0e8ecab commit 28e44d7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion OpenMcdf.Perf/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void MultiStorageAndStreamWrite()
int writeCount = 1024;
byte[] buffer = new byte[32 * 512];

Microsoft.IO.RecyclableMemoryStreamManager manager = new ();
Microsoft.IO.RecyclableMemoryStreamManager manager = new();
Microsoft.IO.RecyclableMemoryStream baseStream = new(manager);
baseStream.Capacity = 2 * (storageCount * buffer.Length * writeCount + storageCount * (streamCount - 1) * buffer.Length);

Expand Down
20 changes: 9 additions & 11 deletions OpenMcdf/DirectoryTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,40 @@ public void Add(DirectoryEntry entry)
return;
}

uint previous = currentEntry!.LeftSiblingId;
uint next = currentEntry.RightSiblingId;

while (true)
{
int compare = DirectoryEntryComparer.Compare(entry.NameCharSpan, currentEntry!.NameCharSpan);
uint leftId = currentEntry!.LeftSiblingId;
uint rightId = currentEntry.RightSiblingId;

int compare = DirectoryEntryComparer.Compare(entry.NameCharSpan, currentEntry.NameCharSpan);
if (compare < 0)
{
if (previous == StreamId.NoStream)
if (leftId == StreamId.NoStream)
{
currentEntry.LeftSiblingId = entry.Id;
directories.Write(currentEntry);
directories.Write(entry);
return;
}

currentEntry = directories.GetDictionaryEntry(previous);
currentEntry = directories.GetDictionaryEntry(leftId);
}
else if (compare > 0)
{
if (next == StreamId.NoStream)
if (rightId == StreamId.NoStream)
{
currentEntry.RightSiblingId = entry.Id;
directories.Write(currentEntry);
directories.Write(entry);
return;
}

currentEntry = directories.GetDictionaryEntry(next);
currentEntry = directories.GetDictionaryEntry(rightId);
}
else
{
throw new IOException($"{entry.Type} \"{entry.NameString}\" already exists.");
}

previous = currentEntry!.LeftSiblingId;
next = currentEntry!.RightSiblingId;
}
}

Expand Down Expand Up @@ -209,6 +206,7 @@ internal void WriteTrace(TextWriter writer)
WriteTrace(writer, current, 0);
}

[ExcludeFromCodeCoverage]
void WriteTrace(TextWriter writer, DirectoryEntry entry, int indent)
{
directories.TryGetDictionaryEntry(entry.RightSiblingId, out DirectoryEntry? rightSibling);
Expand Down
2 changes: 1 addition & 1 deletion OpenMcdf/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public bool TryOpenStorage(string name, [MaybeNullWhen(false)] out Storage? stor

this.ThrowIfDisposed(Context.IsDisposed);

directoryTree.TryGetDirectoryEntry(name, out DirectoryEntry? entry);
directoryTree.TryGetDirectoryEntry(name, out DirectoryEntry? entry);
if (entry is null || entry.Type is not StorageType.Storage)
{
storage = null;
Expand Down
2 changes: 1 addition & 1 deletion StructuredStorageExplorer/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define OLE_PROPERTY

using OpenMcdf.Ole;
using OpenMcdf;
using OpenMcdf.Ole;
using StructuredStorageExplorer.Properties;
using System.Collections;
using System.ComponentModel;
Expand Down

0 comments on commit 28e44d7

Please sign in to comment.