This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
The following commit(s) were added to refs/heads/master by this push: new 5909e3eb Lookup key in map only once 5909e3eb is described below commit 5909e3eb38f6f8bd086fcbdfc728185f9f0c0d6f Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Nov 30 16:52:43 2022 -0500 Lookup key in map only once --- src/main/java/org/apache/commons/text/similarity/Counter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/text/similarity/Counter.java b/src/main/java/org/apache/commons/text/similarity/Counter.java index b73a763a..9170f6d2 100644 --- a/src/main/java/org/apache/commons/text/similarity/Counter.java +++ b/src/main/java/org/apache/commons/text/similarity/Counter.java @@ -42,7 +42,8 @@ final class Counter { public static Map<CharSequence, Integer> of(final CharSequence[] tokens) { final Map<CharSequence, Integer> innerCounter = new HashMap<>(); for (final CharSequence token : tokens) { - innerCounter.put(token, innerCounter.containsKey(token) ? innerCounter.get(token) + 1 : 1); + final Integer integer = innerCounter.get(token); + innerCounter.put(token, integer != null ? integer + 1 : 1); } return innerCounter; }