Skip to content

Commit

Permalink
PERFORMANCE: Lucene.Net.Analysis.TokenAttributes.CharTermAttribute::A…
Browse files Browse the repository at this point in the history
…ppend(): Use StringBuilder.CopyTo() to copy the chars instead of allocating a string.
  • Loading branch information
NightOwl888 committed Jan 19, 2024
1 parent 8c3af72 commit d740f13
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ public CharTermAttribute Append(StringBuilder value)
return this; // No-op
}

return Append(value.ToString());
int len = value.Length;
value.CopyTo(0, InternalResizeBuffer(termLength + len), termLength, len);
Length += len;
return this;
}

public CharTermAttribute Append(StringBuilder value, int startIndex, int charCount)
Expand All @@ -301,7 +304,9 @@ public CharTermAttribute Append(StringBuilder value, int startIndex, int charCou
if (startIndex > value.Length - charCount)
throw new ArgumentOutOfRangeException(nameof(startIndex), $"Index and length must refer to a location within the string. For example {nameof(startIndex)} + {nameof(charCount)} <= {nameof(Length)}.");

return Append(value.ToString(startIndex, charCount));
value.CopyTo(startIndex, InternalResizeBuffer(termLength + charCount), termLength, charCount);
Length += charCount;
return this;
}

public CharTermAttribute Append(ICharTermAttribute value)
Expand Down

0 comments on commit d740f13

Please sign in to comment.