[
https://issues.apache.org/jira/browse/LANG-1523?focusedWorklogId=397497&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-397497
]
ASF GitHub Bot logged work on LANG-1523:
----------------------------------------
Author: ASF GitHub Bot
Created on: 04/Mar/20 11:04
Start Date: 04/Mar/20 11:04
Worklog Time Spent: 10m
Work Description: nstdio commented on pull request #496: LANG-1523: Avoid
unnecessary allocation in StringUtils.wrapIfMissing.
URL: https://github.com/apache/commons-lang/pull/496#discussion_r387595656
##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -9508,20 +9514,27 @@ public static String wrapIfMissing(final String str,
final char wrapWith) {
* @param str
* the string to be wrapped, may be {@code null}
* @param wrapWith
- * the char that will wrap {@code str}
+ * the string that will wrap {@code str}
* @return the wrapped string, or {@code null} if {@code str==null}
* @since 3.5
*/
public static String wrapIfMissing(final String str, final String
wrapWith) {
if (isEmpty(str) || isEmpty(wrapWith)) {
return str;
}
+
+ final boolean wrapStart = !str.startsWith(wrapWith);
+ final boolean wrapEnd = !str.endsWith(wrapWith);
+ if (!wrapStart && !wrapEnd) {
+ return str;
+ }
+
final StringBuilder builder = new StringBuilder(str.length() +
wrapWith.length() + wrapWith.length());
Review comment:
@garydgregory Sure, that makes sense. Done.
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 397497)
Time Spent: 0.5h (was: 20m)
> Avoid unnecessary allocation in StringUtils.wrapIfMissing
> ---------------------------------------------------------
>
> Key: LANG-1523
> URL: https://issues.apache.org/jira/browse/LANG-1523
> Project: Commons Lang
> Issue Type: Improvement
> Components: lang.*
> Affects Versions: 3.9
> Reporter: Edgar Asatryan
> Priority: Major
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> The *StringUtils.wrapIfMissing* creates a new instance of *StringBuilder*
> regardless of whether the input is wrapped or not.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)