[ 
https://issues.apache.org/jira/browse/ARTEMIS-1616?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16334608#comment-16334608
 ] 

ASF GitHub Bot commented on ARTEMIS-1616:
-----------------------------------------

Github user michaelandrepearce commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/1786#discussion_r163012542
  
    --- 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 --
    
    @franz1981 just thinking on this is it worth making the other array list 
also 3? Just so both is consistent, maybe make it a constant, so if in future 
it changes again, single change would affect both.


> OpenWire improvements
> ---------------------
>
>                 Key: ARTEMIS-1616
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-1616
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Francesco Nigro
>            Assignee: Francesco Nigro
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to