lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [21/50] [abbrv] lucenenet git commit: SWEEP: Moved Intern() functionality to StringExtensions and accounted for .NET Standard 1.x's lack of support for it.
Date Sat, 09 Sep 2017 00:31:39 GMT
SWEEP: Moved Intern() functionality to StringExtensions and accounted for .NET Standard 1.x's
lack of support for it.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/e7375db1
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/e7375db1
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/e7375db1

Branch: refs/heads/master
Commit: e7375db12daea3512204964868fe88abe0238445
Parents: afb2e0f
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Thu Sep 7 01:11:44 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Sep 7 01:11:44 2017 +0700

----------------------------------------------------------------------
 .../Support/Sax/Helpers/NamespaceSupport.cs     |  2 +-
 .../Support/StringExtensions.cs                 | 14 -----------
 .../Highlight/QueryScorer.cs                    |  4 ++--
 .../Highlight/QueryTermExtractor.cs             |  8 +++----
 .../Highlight/WeightedSpanTermExtractor.cs      |  6 ++---
 .../Codecs/Lucene3x/TestSurrogates.cs           |  2 +-
 .../Codecs/Lucene3x/Lucene3xFields.cs           |  3 ++-
 src/Lucene.Net/Codecs/Lucene3x/TermBuffer.cs    |  4 ++--
 src/Lucene.Net/Support/StringExtensions.cs      | 25 ++++++++++++++++++++
 src/Lucene.Net/Util/StringHelper.cs             | 13 ----------
 10 files changed, 40 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net.Benchmark/Support/Sax/Helpers/NamespaceSupport.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/Sax/Helpers/NamespaceSupport.cs b/src/Lucene.Net.Benchmark/Support/Sax/Helpers/NamespaceSupport.cs
index 4034dad..c1c81d3 100644
--- a/src/Lucene.Net.Benchmark/Support/Sax/Helpers/NamespaceSupport.cs
+++ b/src/Lucene.Net.Benchmark/Support/Sax/Helpers/NamespaceSupport.cs
@@ -312,7 +312,7 @@ namespace Sax.Helpers
         /// is an undeclared prefix.
         /// </returns>
         /// <seealso cref="DeclarePrefix" />
-        /// <seealso cref="string.Intern(string)" />
+        /// <seealso cref="StringExtensions.Intern(string)" />
         public string[] ProcessName(string qName, string[] parts, bool isAttribute)
         {
             string[] myParts = currentContext.ProcessName(qName, isAttribute);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net.Benchmark/Support/StringExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/StringExtensions.cs b/src/Lucene.Net.Benchmark/Support/StringExtensions.cs
deleted file mode 100644
index 4d67c63..0000000
--- a/src/Lucene.Net.Benchmark/Support/StringExtensions.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace Lucene.Net.Support
-{
-    public static class StringExtensions
-    {
-        public static string Intern(this string value)
-        {
-#if NETSTANDARD1_5
-            return value; // LUCENENET TODO: Fix string interning
-#else
-            return string.Intern(value);
-#endif
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net.Highlighter/Highlight/QueryScorer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Highlighter/Highlight/QueryScorer.cs b/src/Lucene.Net.Highlighter/Highlight/QueryScorer.cs
index b57ac5c..d44a446 100644
--- a/src/Lucene.Net.Highlighter/Highlight/QueryScorer.cs
+++ b/src/Lucene.Net.Highlighter/Highlight/QueryScorer.cs
@@ -88,7 +88,7 @@ namespace Lucene.Net.Search.Highlight
         /// <param name="defaultField">The default field for queries with the field
name unspecified</param>
         public QueryScorer(Query query, IndexReader reader, string field, string defaultField)
         {
-            this.defaultField = StringHelper.Intern(defaultField);
+            this.defaultField = defaultField.Intern();
             Init(query, field, reader, true);
         }
 
@@ -100,7 +100,7 @@ namespace Lucene.Net.Search.Highlight
         /// <param name="defaultField">The default field for queries with the field
name unspecified</param>
         public QueryScorer(Query query, string field, string defaultField)
         {
-            this.defaultField = StringHelper.Intern(defaultField);
+            this.defaultField = defaultField.Intern();
             Init(query, field, null, true);
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs b/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs
index 9901e90..ec8de66 100644
--- a/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs
+++ b/src/Lucene.Net.Highlighter/Highlight/QueryTermExtractor.cs
@@ -1,9 +1,9 @@
-using System;
+using Lucene.Net.Index;
+using Lucene.Net.Support;
+using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using Lucene.Net.Index;
-using Lucene.Net.Util;
 
 namespace Lucene.Net.Search.Highlight
 {
@@ -82,7 +82,7 @@ namespace Lucene.Net.Search.Highlight
             var terms = new HashSet<WeightedTerm>();
             if (fieldName != null)
             {
-                fieldName = StringHelper.Intern(fieldName);
+                fieldName = fieldName.Intern();
             }
             GetTerms(query, terms, prohibited, fieldName);
             return terms.ToArray();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs b/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs
index 25b2cbe..01a21ae 100644
--- a/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs
+++ b/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs
@@ -51,7 +51,7 @@ namespace Lucene.Net.Search.Highlight
         {
             if (defaultField != null)
             {
-                this.defaultField = StringHelper.Intern(defaultField);
+                this.defaultField = defaultField.Intern();
             }
         }
 
@@ -487,7 +487,7 @@ namespace Lucene.Net.Search.Highlight
         {
             if (fieldName != null)
             {
-                this.fieldName = StringHelper.Intern(fieldName);
+                this.fieldName = fieldName.Intern();
             }
             else
             {
@@ -521,7 +521,7 @@ namespace Lucene.Net.Search.Highlight
         public virtual IDictionary<string, WeightedSpanTerm> GetWeightedSpanTermsWithScores(
             Query query, TokenStream tokenStream, string fieldName, IndexReader reader)
         {
-            this.fieldName = fieldName == null ? null : StringHelper.Intern(fieldName);
+            this.fieldName = fieldName == null ? null : fieldName.Intern();
 
             this.tokenStream = tokenStream;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
index f46122f..53b69e3 100644
--- a/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
+++ b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
@@ -261,7 +261,7 @@ namespace Lucene.Net.Codecs.Lucene3x
                 for (int iter = 0; iter < num; iter++)
                 {
                     // seek to random spot
-                    string field = StringHelper.Intern("f" + r.Next(numField));
+                    string field = ("f" + r.Next(numField)).Intern();
                     Term tx = new Term(field, GetRandomString(r));
 
                     int spot = Array.BinarySearch(fieldTermsArray, tx);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs
index a98f2f1..a95fe11 100644
--- a/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs
+++ b/src/Lucene.Net/Codecs/Lucene3x/Lucene3xFields.cs
@@ -1,4 +1,5 @@
 using Lucene.Net.Index;
+using Lucene.Net.Support;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
@@ -798,7 +799,7 @@ namespace Lucene.Net.Codecs.Lucene3x
                 //System.out.println("pff.reset te=" + termEnum);
                 this.fieldInfo = fieldInfo;
                 
-                internedFieldName = StringHelper.Intern(fieldInfo.Name);
+                internedFieldName = fieldInfo.Name.Intern();
 
                 Term term = new Term(internedFieldName);
                 if (termEnum == null)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net/Codecs/Lucene3x/TermBuffer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Codecs/Lucene3x/TermBuffer.cs b/src/Lucene.Net/Codecs/Lucene3x/TermBuffer.cs
index 61f3504..318edce 100644
--- a/src/Lucene.Net/Codecs/Lucene3x/TermBuffer.cs
+++ b/src/Lucene.Net/Codecs/Lucene3x/TermBuffer.cs
@@ -86,7 +86,7 @@ namespace Lucene.Net.Codecs.Lucene3x
                 {
                     Debug.Assert(fieldInfos.FieldInfo(currentFieldNumber) != null, currentFieldNumber.ToString());
                     
-                    field = StringHelper.Intern(fieldInfos.FieldInfo(currentFieldNumber).Name);
+                    field = fieldInfos.FieldInfo(currentFieldNumber).Name.Intern();
                 }
             }
             else
@@ -106,7 +106,7 @@ namespace Lucene.Net.Codecs.Lucene3x
                 return;
             }
             bytes.CopyBytes(term.Bytes);
-            field = StringHelper.Intern(term.Field);
+            field = term.Field.Intern();
 
             currentFieldNumber = -1;
             this.term = term;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net/Support/StringExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/StringExtensions.cs b/src/Lucene.Net/Support/StringExtensions.cs
index b8e4bbd..0bb596b 100644
--- a/src/Lucene.Net/Support/StringExtensions.cs
+++ b/src/Lucene.Net/Support/StringExtensions.cs
@@ -166,5 +166,30 @@ namespace Lucene.Net.Support
             }
             return input;
         }
+
+
+        /// <summary> Expert:
+        /// The StringInterner implementation used by Lucene.
+        /// This shouldn't be changed to an incompatible implementation after other Lucene
APIs have been used.
+        /// LUCENENET specific.
+        /// </summary>
+        private static StringInterner interner =
+#if NETSTANDARD1_5
+            new SimpleStringInterner(1024, 8);
+#else
+            new StringInterner();
+#endif
+
+        /// <summary>
+        /// Searches an internal table of strings for a string equal to this string.
+        /// If the string is not in the table, it is added. Returns the string
+        /// contained in the table which is equal to this string. The same string
+        /// object is always returned for strings which are equal.
+        /// </summary>
+        /// <returns>The interned string equal to this string.</returns>
+        public static string Intern(this string s)
+        {
+            return interner.Intern(s);
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e7375db1/src/Lucene.Net/Util/StringHelper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Util/StringHelper.cs b/src/Lucene.Net/Util/StringHelper.cs
index 1e1ebc4..a728c2c 100644
--- a/src/Lucene.Net/Util/StringHelper.cs
+++ b/src/Lucene.Net/Util/StringHelper.cs
@@ -28,19 +28,6 @@ namespace Lucene.Net.Util
     /// </summary>
     public abstract class StringHelper
     {
-        /// <summary> Expert:
-        /// The StringInterner implementation used by Lucene.
-        /// This shouldn't be changed to an incompatible implementation after other Lucene
APIs have been used.
-        /// LUCENENET specific.
-        /// </summary>
-        public static StringInterner interner = new SimpleStringInterner(1024, 8);
-
-        /// <summary>Returns the same string object for all equal strings.</summary>
-        public static System.String Intern(System.String s)
-        {
-            return interner.Intern(s);
-        }
-
         /// <summary>
         /// Compares two <see cref="BytesRef"/>, element by element, and returns the
         /// number of elements common to both arrays.


Mime
View raw message