Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7E382200D02 for ; Sat, 9 Sep 2017 02:31:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7D05C160F14; Sat, 9 Sep 2017 00:31:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 74DF01609DA for ; Sat, 9 Sep 2017 02:31:22 +0200 (CEST) Received: (qmail 47120 invoked by uid 500); 9 Sep 2017 00:31:21 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 45521 invoked by uid 99); 9 Sep 2017 00:31:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Sep 2017 00:31:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A228DF5715; Sat, 9 Sep 2017 00:31:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: nightowl888@apache.org To: commits@lucenenet.apache.org Date: Sat, 09 Sep 2017 00:31:39 -0000 Message-Id: <323002e468104959a347399942a4aa1c@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer 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. archived-at: Sat, 09 Sep 2017 00:31:23 -0000 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 Authored: Thu Sep 7 01:11:44 2017 +0700 Committer: Shad Storhaug 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. /// /// - /// + /// 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 /// The default field for queries with the field name unspecified 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 /// The default field for queries with the field name unspecified 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(); 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 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; } + + + /// 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. + /// + private static StringInterner interner = +#if NETSTANDARD1_5 + new SimpleStringInterner(1024, 8); +#else + new StringInterner(); +#endif + + /// + /// 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. + /// + /// The interned string equal to this string. + 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 /// public abstract class StringHelper { - /// 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. - /// - public static StringInterner interner = new SimpleStringInterner(1024, 8); - - /// Returns the same string object for all equal strings. - public static System.String Intern(System.String s) - { - return interner.Intern(s); - } - /// /// Compares two , element by element, and returns the /// number of elements common to both arrays.