Skip to content

Commit

Permalink
Lazy-initialize MessageSummary.Keywords
Browse files Browse the repository at this point in the history
This reduces memory usage when the client isn't requesting Flags/Keywords.

Part of a set of ongoing fixes for issue #1335
  • Loading branch information
jstedfast committed Mar 5, 2022
1 parent ab1e087 commit a736d88
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions MailKit/MessageSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace MailKit {
/// </remarks>
public class MessageSummary : IMessageSummary
{
IReadOnlySetOfStrings keywords;
int threadableReplyDepth = -1;
string normalizedSubject;

Expand All @@ -68,7 +69,6 @@ public MessageSummary (int index)
if (index < 0)
throw new ArgumentOutOfRangeException (nameof (index));

Keywords = new HashSet<string> (StringComparer.Ordinal);
Index = index;
}

Expand Down Expand Up @@ -492,7 +492,15 @@ public MessageFlags? Flags {
/// </remarks>
/// <value>The user-defined message flags.</value>
public IReadOnlySetOfStrings Keywords {
get; set;
get {
if (keywords == null)
keywords = new HashSet<string> (StringComparer.Ordinal);

return keywords;
}
set {
keywords = value;
}
}

/// <summary>
Expand Down

0 comments on commit a736d88

Please sign in to comment.