FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Specify an initial capacity when creating the property lists by Numpsy · Pull Request #423 · openmcdf/openmcdf · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
53 changes: 32 additions & 21 deletions OpenMcdf.Ole/OlePropertiesContainer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class OlePropertiesContainer

public PropertyContext Context { get; }

private readonly List<OleProperty> properties = new();
private readonly List<OleProperty> properties;

/// <summary>
/// Initializes a new instance of the <see cref="OlePropertiesContainer"/> class.
Expand All @@ -48,6 +48,7 @@ public OlePropertiesContainer(int codePage, ContainerType containerType)

ContainerType = containerType;
FMTID0 = FmtIdFromContainerType(containerType);
properties = [];
}

public OlePropertiesContainer(CfbStream cfStream)
Expand All @@ -64,6 +65,7 @@ public OlePropertiesContainer(CfbStream cfStream)
.FirstOrDefault(p => p.PropertyType == PropertyType.DictionaryProperty)?.Value;

Context = pStream.PropertySet0.PropertyContext;
properties = new(pStream.PropertySet0.Properties.Count);

for (int i = 0; i < pStream.PropertySet0.Properties.Count; i++)
{
Expand All @@ -83,34 +85,43 @@ public OlePropertiesContainer(CfbStream cfStream)
properties.Add(op);
}

// Build the User Defined properties container, if the property set is present.
if (pStream.NumPropertySets == 2)

Numpsy Apr 29, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

On a related note (not part of this change, something that could be a separate issue) - the PropertySetStream documentation states

The current logic always reads the second property set if present, but it could validate this requirement (same on writing - making sure it doesn't write the UserDefinedProperties set for any parent other than DocSummaryInformation may or may not be something that could be controlled by a strict validation flag

{
PropertySet propertySet1 = pStream.PropertySet1!;
UserDefinedProperties = new OlePropertiesContainer(propertySet1.PropertyContext.CodePage, ContainerType.UserDefinedProperties);

for (int i = 0; i < propertySet1.Properties.Count; i++)
{
PropertyIdentifierAndOffset propertyIdentifierAndOffset = propertySet1.PropertyIdentifierAndOffsets[i];
if (propertyIdentifierAndOffset.PropertyIdentifier is SpecialPropertyIdentifiers.Dictionary or SpecialPropertyIdentifiers.Locale)
continue;
UserDefinedProperties = new OlePropertiesContainer(pStream.PropertySet1!);
}
}

var p = (ITypedPropertyValue)propertySet1.Properties[i];
// An extra private constructor used to build the UserDefinedProperties property set, if one is present in the file.
private OlePropertiesContainer(PropertySet propertySet)
{
ContainerType = ContainerType.UserDefinedProperties;
Context = propertySet.PropertyContext;
FMTID0 = FormatIdentifiers.UserDefinedProperties;
properties = new(propertySet.Properties.Count);

OleProperty op = new(UserDefinedProperties)
{
VTType = p.VTType,
PropertyIdentifier = propertyIdentifierAndOffset.PropertyIdentifier,
Value = p.Value,
};
for (int i = 0; i < propertySet.Properties.Count; i++)
{
PropertyIdentifierAndOffset propertyIdentifierAndOffset = propertySet.PropertyIdentifierAndOffsets[i];
if (propertyIdentifierAndOffset.PropertyIdentifier is SpecialPropertyIdentifiers.Dictionary or SpecialPropertyIdentifiers.Locale)
continue;

UserDefinedProperties.properties.Add(op);
}
var p = (ITypedPropertyValue)propertySet.Properties[i];

var existingPropertyNames = (Dictionary<uint, string>?)propertySet1.Properties
.FirstOrDefault(p => p.PropertyType == PropertyType.DictionaryProperty)?.Value;
OleProperty op = new(this)
{
VTType = p.VTType,
PropertyIdentifier = propertyIdentifierAndOffset.PropertyIdentifier,
Value = p.Value,
};

UserDefinedProperties.PropertyNames = existingPropertyNames ?? new Dictionary<uint, string>();
properties.Add(op);
}

var existingPropertyNames = (Dictionary<uint, string>?)propertySet.Properties
.FirstOrDefault(p => p.PropertyType == PropertyType.DictionaryProperty)?.Value;

PropertyNames = existingPropertyNames ?? [];
}

public IList<OleProperty> Properties => properties;
Expand Down

Back | FazBrowse Home | New Git URL