You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2020/06/10 03:25:26 UTC

[GitHub] [rocketmq] yejiahao opened a new issue #2082: StringBuffer or StringBuilder

yejiahao opened a new issue #2082:
URL: https://github.com/apache/rocketmq/issues/2082


   I have seen the source code
   **NamespaceUtil#wrapNamespace**
   ```java
   public static String wrapNamespace(String namespace, String resourceWithOutNamespace) {
   	// ...
   	StringBuffer strBuffer = new StringBuffer();
   
   	if (isRetryTopic(resourceWithOutNamespace)) {
   		strBuffer.append(MixAll.RETRY_GROUP_TOPIC_PREFIX);
   	}
   
   	if (isDLQTopic(resourceWithOutNamespace)) {
   		strBuffer.append(MixAll.DLQ_GROUP_TOPIC_PREFIX);
   	}
   
   	return strBuffer.append(namespace).append(NAMESPACE_SEPARATOR).append(resourceWithoutRetryAndDLQ).toString();
   
   }
   ```
   Maybe use ```StringBuilder``` is better because I think it is local variable level and obj doesn't "escape" from this method.
   
   Feel free to reply for studying, thanks.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] RosaDreaming commented on issue #2082: StringBuffer or StringBuilder

Posted by GitBox <gi...@apache.org>.
RosaDreaming commented on issue #2082:
URL: https://github.com/apache/rocketmq/issues/2082#issuecomment-642368263


   > > I have seen the source code
   > > **NamespaceUtil#wrapNamespace**
   > > ```java
   > > public static String wrapNamespace(String namespace, String resourceWithOutNamespace) {
   > > 	// ...
   > > 	StringBuffer strBuffer = new StringBuffer();
   > > 
   > > 	if (isRetryTopic(resourceWithOutNamespace)) {
   > > 		strBuffer.append(MixAll.RETRY_GROUP_TOPIC_PREFIX);
   > > 	}
   > > 
   > > 	if (isDLQTopic(resourceWithOutNamespace)) {
   > > 		strBuffer.append(MixAll.DLQ_GROUP_TOPIC_PREFIX);
   > > 	}
   > > 
   > > 	return strBuffer.append(namespace).append(NAMESPACE_SEPARATOR).append(resourceWithoutRetryAndDLQ).toString();
   > > 
   > > }
   > > ```
   > > 
   > > 
   > > Maybe use `StringBuilder` is better because I think it is local variable level and obj doesn't "escape" from this method.
   > > Feel free to reply for studying, thanks.
   > 
   > yep, StringBuilder performs better in this case.
   
   i can create a new pr to solve this problem.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] lebron374 commented on issue #2082: StringBuffer or StringBuilder

Posted by GitBox <gi...@apache.org>.
lebron374 commented on issue #2082:
URL: https://github.com/apache/rocketmq/issues/2082#issuecomment-642974822


   > > > I have seen the source code
   > > > **NamespaceUtil#wrapNamespace**
   > > > ```java
   > > > public static String wrapNamespace(String namespace, String resourceWithOutNamespace) {
   > > > 	// ...
   > > > 	StringBuffer strBuffer = new StringBuffer();
   > > > 
   > > > 	if (isRetryTopic(resourceWithOutNamespace)) {
   > > > 		strBuffer.append(MixAll.RETRY_GROUP_TOPIC_PREFIX);
   > > > 	}
   > > > 
   > > > 	if (isDLQTopic(resourceWithOutNamespace)) {
   > > > 		strBuffer.append(MixAll.DLQ_GROUP_TOPIC_PREFIX);
   > > > 	}
   > > > 
   > > > 	return strBuffer.append(namespace).append(NAMESPACE_SEPARATOR).append(resourceWithoutRetryAndDLQ).toString();
   > > > 
   > > > }
   > > > ```
   > > > 
   > > > 
   > > > Maybe use `StringBuilder` is better because I think it is local variable level and obj doesn't "escape" from this method.
   > > > Feel free to reply for studying, thanks.
   > > 
   > > 
   > > yep, StringBuilder performs better in this case.
   > 
   > i can create a new pr to solve this problem.
   
   good job


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] RongtongJin closed issue #2082: StringBuffer or StringBuilder

Posted by GitBox <gi...@apache.org>.
RongtongJin closed issue #2082:
URL: https://github.com/apache/rocketmq/issues/2082


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] lizhiboo commented on issue #2082: StringBuffer or StringBuilder

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on issue #2082:
URL: https://github.com/apache/rocketmq/issues/2082#issuecomment-641942366


   > I have seen the source code
   > **NamespaceUtil#wrapNamespace**
   > 
   > ```java
   > public static String wrapNamespace(String namespace, String resourceWithOutNamespace) {
   > 	// ...
   > 	StringBuffer strBuffer = new StringBuffer();
   > 
   > 	if (isRetryTopic(resourceWithOutNamespace)) {
   > 		strBuffer.append(MixAll.RETRY_GROUP_TOPIC_PREFIX);
   > 	}
   > 
   > 	if (isDLQTopic(resourceWithOutNamespace)) {
   > 		strBuffer.append(MixAll.DLQ_GROUP_TOPIC_PREFIX);
   > 	}
   > 
   > 	return strBuffer.append(namespace).append(NAMESPACE_SEPARATOR).append(resourceWithoutRetryAndDLQ).toString();
   > 
   > }
   > ```
   > 
   > Maybe use `StringBuilder` is better because I think it is local variable level and obj doesn't "escape" from this method.
   > 
   > Feel free to reply for studying, thanks.
   
   yep, StringBuilder performs better in this case.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org