lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject [1/4] lucene-solr:master: LUCENE-7743: Avoid calling new String(String).
Date Tue, 28 Mar 2017 14:10:48 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 68eb078af -> 390ef9af9


LUCENE-7743: Avoid calling new String(String).


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/390ef9af
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/390ef9af
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/390ef9af

Branch: refs/heads/master
Commit: 390ef9af9fa081c90370f69b001cf7ec83c8f1bb
Parents: c189139
Author: Adrien Grand <jpountz@gmail.com>
Authored: Tue Mar 28 15:25:16 2017 +0200
Committer: Adrien Grand <jpountz@gmail.com>
Committed: Tue Mar 28 15:35:04 2017 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                           | 3 +++
 .../lucene/analysis/compound/hyphenation/TernaryTree.java    | 2 +-
 .../java/org/apache/lucene/analysis/cn/smart/Utility.java    | 8 ++++----
 .../src/test/org/apache/lucene/index/TestIndexWriter.java    | 2 +-
 .../test/org/apache/lucene/util/TestRamUsageEstimator.java   | 8 ++++----
 .../solr/handler/dataimport/AbstractDIHCacheTestCase.java    | 2 +-
 .../org/apache/solr/highlight/DefaultSolrHighlighter.java    | 3 +--
 solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java      | 4 ++--
 .../test/org/apache/solr/response/TestSolrQueryResponse.java | 2 +-
 .../solr/schema/TrieIntPrefixActsAsRangeQueryFieldType.java  | 2 +-
 10 files changed, 19 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index a8f24c7..92f01a9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -90,6 +90,9 @@ Other
 * LUCENE-7751: Avoid boxing primitives only to call compareTo.
   (Daniel Jelinski via Adrien Grand)
 
+* LUCENE-7743: Never call new String(String).
+  (Daniel Jelinski via Adrien Grand)
+
 ======================= Lucene 6.5.0 =======================
 
 API Changes

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
index 6aeb69b..a331d2a 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
@@ -516,7 +516,7 @@ public class TernaryTree implements Cloneable {
 
     @Override
     public String nextElement() {
-      String res = new String(curkey);
+      String res = curkey;
       cur = up();
       run();
       return res;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/Utility.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/Utility.java
b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/Utility.java
index aca80e7..81ca52e 100644
--- a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/Utility.java
+++ b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/Utility.java
@@ -24,16 +24,16 @@ import org.apache.lucene.analysis.cn.smart.hhmm.SegTokenFilter; // for
javadoc
  */
 public class Utility {
 
-  public static final char[] STRING_CHAR_ARRAY = new String("未##串")
+  public static final char[] STRING_CHAR_ARRAY = "未##串"
       .toCharArray();
 
-  public static final char[] NUMBER_CHAR_ARRAY = new String("未##数")
+  public static final char[] NUMBER_CHAR_ARRAY = "未##数"
       .toCharArray();
 
-  public static final char[] START_CHAR_ARRAY = new String("始##始")
+  public static final char[] START_CHAR_ARRAY = "始##始"
       .toCharArray();
 
-  public static final char[] END_CHAR_ARRAY = new String("末##末").toCharArray();
+  public static final char[] END_CHAR_ARRAY = "末##末".toCharArray();
 
   /**
    * Delimiters will be filtered to this character by {@link SegTokenFilter}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
index d153ac3..660280b 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -1154,7 +1154,7 @@ public class TestIndexWriter extends LuceneTestCase {
     t.finish = true;
     t.join();
     if (t.failed) {
-      fail(new String(t.bytesLog.toString("UTF-8")));
+      fail(t.bytesLog.toString("UTF-8"));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
index cf53c2d..34128ad 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
@@ -24,7 +24,7 @@ import java.util.Random;
 
 public class TestRamUsageEstimator extends LuceneTestCase {
   public void testSanity() {
-    assertTrue(sizeOf(new String("test string")) > shallowSizeOfInstance(String.class));
+    assertTrue(sizeOf("test string") > shallowSizeOfInstance(String.class));
 
     Holder holder = new Holder();
     holder.holder = new Holder("string2", 5000L);
@@ -37,9 +37,9 @@ public class TestRamUsageEstimator extends LuceneTestCase {
         shallowSizeOfInstance(Holder.class)         == shallowSizeOfInstance(HolderSubclass2.class));
 
     String[] strings = new String[] {
-        new String("test string"),
-        new String("hollow"), 
-        new String("catchmaster")
+        "test string",
+        "hollow",
+        "catchmaster"
     };
     assertTrue(sizeOf(strings) > shallowSizeOf(strings));
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHCacheTestCase.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHCacheTestCase.java
b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHCacheTestCase.java
index 2ef5a91..8c7109d 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHCacheTestCase.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHCacheTestCase.java
@@ -47,7 +47,7 @@ public class AbstractDIHCacheTestCase {
   @Before
   public void setup() {
     try {
-      APPLE = new SerialClob(new String("Apples grow on trees and they are good to eat.").toCharArray());
+      APPLE = new SerialClob("Apples grow on trees and they are good to eat.".toCharArray());
     } catch (SQLException sqe) {
       Assert.fail("Could not Set up Test");
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
index 098e1f7..24304d0a 100644
--- a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
+++ b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
@@ -733,9 +733,8 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements
PluginInf
       if( alternateFieldLen <= 0 ){
         altList.add(encoder.encodeText(altText));
       } else{
-        //note: seemingly redundant new String(...) releases memory to the larger text. But
is copying better?
         altList.add( len + altText.length() > alternateFieldLen ?
-            encoder.encodeText(new String(altText.substring( 0, alternateFieldLen - len )))
:
+            encoder.encodeText(altText.substring(0, alternateFieldLen - len)) :
             encoder.encodeText(altText) );
         len += altText.length();
         if( len >= alternateFieldLen ) break;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
index 8b29d48..dc999f1 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
@@ -272,7 +272,7 @@ public class ZkCLITest extends SolrTestCaseJ4 {
   @Test
   public void testGet() throws Exception {
     String getNode = "/getNode";
-    byte [] data = new String("getNode-data").getBytes(StandardCharsets.UTF_8);
+    byte [] data = "getNode-data".getBytes(StandardCharsets.UTF_8);
     this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true);
     String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
         "get", getNode};
@@ -284,7 +284,7 @@ public class ZkCLITest extends SolrTestCaseJ4 {
     File tmpDir = createTempDir().toFile();
     
     String getNode = "/getFileNode";
-    byte [] data = new String("getFileNode-data").getBytes(StandardCharsets.UTF_8);
+    byte [] data = "getFileNode-data".getBytes(StandardCharsets.UTF_8);
     this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true);
 
     File file = new File(tmpDir,

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java b/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java
index 8b17dc6..046582f 100644
--- a/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java
+++ b/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java
@@ -79,7 +79,7 @@ public class TestSolrQueryResponse extends LuceneTestCase {
     final SolrQueryResponse response = new SolrQueryResponse();
     assertEquals("response initial value", null, response.getResponse());
     final Object newValue = (random().nextBoolean()
-        ? (random().nextBoolean() ? new String("answer") : new Integer(42)) : null);
+        ? (random().nextBoolean() ? "answer" : Integer.valueOf(42)) : null);
     response.addResponse(newValue);
     assertEquals("response new value", newValue, response.getResponse());
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/390ef9af/solr/core/src/test/org/apache/solr/schema/TrieIntPrefixActsAsRangeQueryFieldType.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/TrieIntPrefixActsAsRangeQueryFieldType.java
b/solr/core/src/test/org/apache/solr/schema/TrieIntPrefixActsAsRangeQueryFieldType.java
index a58c268..4b79975 100644
--- a/solr/core/src/test/org/apache/solr/schema/TrieIntPrefixActsAsRangeQueryFieldType.java
+++ b/solr/core/src/test/org/apache/solr/schema/TrieIntPrefixActsAsRangeQueryFieldType.java
@@ -26,7 +26,7 @@ import org.apache.solr.search.QParser;
 public class TrieIntPrefixActsAsRangeQueryFieldType extends TrieIntField {
 
   public Query getPrefixQuery(QParser parser, SchemaField sf, String termStr) {
-    return getRangeQuery(parser, sf, termStr, new String(Integer.MAX_VALUE + ""), true, false);
+    return getRangeQuery(parser, sf, termStr, Integer.MAX_VALUE + "", true, false);
   }
 
 }


Mime
View raw message