Skip to content

Commit

Permalink
Single StringBuilder allocation per find (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Oct 2, 2023
1 parent 7624248 commit 97bcfd0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions implementation/src/main/java/io/smallrye/config/KeyMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,20 @@ public KeyMap<V> findOrAdd(final String path) {
return findOrAdd(new NameIterator(path));
}

public KeyMap<V> findOrAdd(final NameIterator ni) {
public KeyMap<V> findOrAdd(final NameIterator path) {
return findOrAdd(path, new StringBuilder());
}

KeyMap<V> findOrAdd(final NameIterator ni, final StringBuilder sb) {
if (!ni.hasNext()) {
return this;
}
String seg = ni.getNextSegment();
String seg = ni.getNextSegment(sb).toString();
ni.next();
try {
KeyMap<V> next = getNext(seg);
return next.findOrAdd(ni);
sb.setLength(0);
return next.findOrAdd(ni, sb);
} finally {
ni.previous();
}
Expand Down

0 comments on commit 97bcfd0

Please sign in to comment.