Github user franz1981 commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1786#discussion_r162610245
--- Diff:
artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/SimpleString.java
---
@@ -361,13 +371,68 @@ public int hashCode() {
}
}
+ private static SimpleString[] splitWithCachedString(final SimpleString
simpleString, final int delim) {
+ final String str = simpleString.str;
+ final byte[] data = simpleString.data;
+ final int length = str.length();
+ List<SimpleString> all = null;
+ int index = 0;
+ while (index < length) {
+ final int delimIndex = str.indexOf(delim, index);
+ if (delimIndex == -1) {
+ //just need to add the last one
+ break;
+ } else {
+ all = addSimpleStringPart(all, data, index, delimIndex);
+ }
+ index = delimIndex + 1;
+ }
+ if (all == null) {
+ return new SimpleString[]{simpleString};
+ } else {
+ // Adding the last one
+ all = addSimpleStringPart(all, data, index, length);
+ // Converting it to arrays
+ final SimpleString[] parts = new SimpleString[all.size()];
+ return all.toArray(parts);
+ }
+ }
+
+ private static List<SimpleString>
addSimpleStringPart(List<SimpleString> all,
+ final byte[] data,
+ final int
startIndex,
+ final int
endIndex) {
+ final int expectedLength = endIndex - startIndex;
+ final SimpleString ss;
+ if (expectedLength == 0) {
+ ss = EMPTY;
+ } else {
+ //extract a byte[] copy from this
+ final int ssIndex = startIndex << 1;
+ final int delIndex = endIndex << 1;
+ final byte[] bytes = Arrays.copyOfRange(data, ssIndex, delIndex);
+ ss = new SimpleString(bytes);
+ }
+ // We will create the ArrayList lazily
+ if (all == null) {
+ // There will be at least 3 strings on this case (which is the
actual common usecase)
--- End diff --
Difficult to say: I've found split to be used on AddressImpl mainly and
openwire uses at least 3 parts addresses, while the other protocols seems to
not rely heavily on split.
Probably @clebert has a better knowledge of how he has chosen 2 instead,
wdyt?
---