Skip to content

Commit

Permalink
Reduce Storage DirectoryEntry access
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Nov 17, 2024
1 parent 17626c3 commit f4bf712
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions OpenMcdf/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ namespace OpenMcdf;
public class Storage : ContextBase
{
readonly DirectoryTree directoryTree;
readonly DirectoryEntry directoryEntry;
readonly string path;

internal DirectoryEntry DirectoryEntry { get; }

public Storage? Parent { get; }

internal Storage(RootContextSite rootContextSite, DirectoryEntry directoryEntry, Storage? parent)
Expand All @@ -21,50 +20,50 @@ internal Storage(RootContextSite rootContextSite, DirectoryEntry directoryEntry,
throw new ArgumentException("DirectoryEntry must be a Storage or Root.", nameof(directoryEntry));

directoryTree = new(Context.DirectoryEntries, directoryEntry);
DirectoryEntry = directoryEntry;
this.directoryEntry = directoryEntry;
Parent = parent;
path = parent is null ? $"/" : $"{parent.path}{parent.EntryInfo.Name}/";
}

public EntryInfo EntryInfo => DirectoryEntry.ToEntryInfo(path);
public EntryInfo EntryInfo => directoryEntry.ToEntryInfo(path);

public Guid CLISD
{
get => DirectoryEntry.CLSID;
get => directoryEntry.CLSID;
set
{
DirectoryEntry.CLSID = value;
Context.DirectoryEntries.Write(DirectoryEntry);
directoryEntry.CLSID = value;
Context.DirectoryEntries.Write(directoryEntry);
}
}

public DateTime CreationTime
{
get => DirectoryEntry.CreationTime;
get => directoryEntry.CreationTime;
set
{
DirectoryEntry.CreationTime = value;
Context.DirectoryEntries.Write(DirectoryEntry);
directoryEntry.CreationTime = value;
Context.DirectoryEntries.Write(directoryEntry);
}
}

public DateTime ModifiedTime
{
get => DirectoryEntry.ModifiedTime;
get => directoryEntry.ModifiedTime;
set
{
DirectoryEntry.ModifiedTime = value;
Context.DirectoryEntries.Write(DirectoryEntry);
directoryEntry.ModifiedTime = value;
Context.DirectoryEntries.Write(directoryEntry);
}
}

public uint StateBits
{
get => DirectoryEntry.StateBits;
get => directoryEntry.StateBits;
set
{
DirectoryEntry.StateBits = value;
Context.DirectoryEntries.Write(DirectoryEntry);
directoryEntry.StateBits = value;
Context.DirectoryEntries.Write(directoryEntry);
}
}

Expand All @@ -80,7 +79,7 @@ public IEnumerable<EntryInfo> EnumerateEntries()

IEnumerable<DirectoryEntry> EnumerateDirectoryEntries()
{
using DirectoryTreeEnumerator treeEnumerator = new(Context.DirectoryEntries, DirectoryEntry);
using DirectoryTreeEnumerator treeEnumerator = new(Context.DirectoryEntries, directoryEntry);
while (treeEnumerator.MoveNext())
{
yield return treeEnumerator.Current;
Expand Down

0 comments on commit f4bf712

Please sign in to comment.