This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit d740f13ea160e3fcd556c497fd7e095c8a8c81d0
Author: Shad Storhaug <[email protected]>
AuthorDate: Fri Jan 19 15:45:22 2024 +0700

    PERFORMANCE: 
Lucene.Net.Analysis.TokenAttributes.CharTermAttribute::Append(): Use 
StringBuilder.CopyTo() to copy the chars instead of allocating a string.
---
 src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs 
b/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs
index c37541b40..bd04b96d0 100644
--- a/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs
+++ b/src/Lucene.Net/Analysis/TokenAttributes/CharTermAttributeImpl.cs
@@ -279,7 +279,10 @@ namespace Lucene.Net.Analysis.TokenAttributes
                 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)
@@ -301,7 +304,9 @@ namespace Lucene.Net.Analysis.TokenAttributes
             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)

Reply via email to