You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by gu...@apache.org on 2021/07/27 01:36:10 UTC
[solr] branch main updated: SOLR-15559 Small optimization in
StrUtils.splitSmart() (#235)
This is an automated email from the ASF dual-hosted git repository.
gus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 5e8857c SOLR-15559 Small optimization in StrUtils.splitSmart() (#235)
5e8857c is described below
commit 5e8857c62e6864001c729cd21ddf29d23441b8ca
Author: Gus Heck <46...@users.noreply.github.com>
AuthorDate: Mon Jul 26 21:36:00 2021 -0400
SOLR-15559 Small optimization in StrUtils.splitSmart() (#235)
---
.../src/java/org/apache/solr/common/util/StrUtils.java | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/StrUtils.java b/solr/solrj/src/java/org/apache/solr/common/util/StrUtils.java
index a202652..09d4095 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/StrUtils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/StrUtils.java
@@ -17,6 +17,7 @@
package org.apache.solr.common.util;
import java.io.IOException;
+import java.nio.CharBuffer;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -112,13 +113,13 @@ public class StrUtils {
*/
public static List<String> splitSmart(String s, String separator, boolean decode) {
ArrayList<String> lst = new ArrayList<>(2);
- StringBuilder sb = new StringBuilder();
+ CharBuffer buffer = CharBuffer.allocate(s.length());
int pos = 0, end = s.length();
while (pos < end) {
if (s.startsWith(separator, pos)) {
- if (sb.length() > 0) {
- lst.add(sb.toString());
- sb = new StringBuilder();
+ if (buffer.position() > 0) {
+ lst.add(buffer.flip().toString());
+ buffer.clear();
}
pos += separator.length();
continue;
@@ -126,7 +127,7 @@ public class StrUtils {
char ch = s.charAt(pos++);
if (ch == '\\') {
- if (!decode) sb.append(ch);
+ if (!decode) buffer.append(ch);
if (pos >= end) break; // ERROR, or let it go?
ch = s.charAt(pos++);
if (decode) {
@@ -150,11 +151,11 @@ public class StrUtils {
}
}
- sb.append(ch);
+ buffer.append(ch);
}
- if (sb.length() > 0) {
- lst.add(sb.toString());
+ if (buffer.position() > 0) {
+ lst.add(buffer.flip().toString());
}
return lst;