[ 
https://issues.apache.org/jira/browse/OAK-12044?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Nuno Santos resolved OAK-12044.
-------------------------------
    Fix Version/s: 1.90.0
       Resolution: Done

> Optimize PathUtils.concat
> -------------------------
>
>                 Key: OAK-12044
>                 URL: https://issues.apache.org/jira/browse/OAK-12044
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: commons
>            Reporter: Nuno Santos
>            Priority: Minor
>             Fix For: 1.90.0
>
>
> The current logicĀ uses the same String concatenation statement for both the 
> cases where the separator is an empty String and when it is a "/".
> {code:java}
> String separator = denotesRootPath(parentPath) ? "" : "/";
> return parentPath + separator + subPath;
> {code}
> [https://github.com/apache/jackrabbit-oak/blob/251fde23e03a4cc1d92e06a64ff6f52f619295f2/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java#L320-L321]
> In this case, invokedynamic will compile this logic into a call to a method 
> that takes 3 arguments and concatenates them. This is wasteful when the 
> separator is an empty string. A better alternative is to split the two paths, 
> like this:
> {code:java}
> if (denotesRootPath(parentPath)) {
>     return parentPath + subPath;
> } else {
>     return parentPath + "/" + subPath;
> }
> {code}
> This will speed-up the case where the parentPath is root, as invokedynamic 
> will use a 2 argument version of the concat operator. It is arguably also 
> more clear to read.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to