Skip to content

Commit aeacbbd

Browse files
committed
Sync with underscore-java.
1 parent 7ea7d4d commit aeacbbd

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/main/java/com/github/underscore/MemoizeFunction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ public abstract class MemoizeFunction<F, T> implements Function<F, T> {
3333
public abstract T calc(final F n);
3434

3535
public T apply(final F key) {
36-
if (!cache.containsKey(key)) {
37-
cache.put(key, calc(key));
38-
}
36+
cache.putIfAbsent(key, calc(key));
3937
return cache.get(key);
4038
}
4139
}

src/main/java/com/github/underscore/U.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ public byte[] blob() {
19451945

19461946
public String text() {
19471947
try {
1948-
return stream.toString("UTF-8");
1948+
return stream.toString(StandardCharsets.UTF_8.name());
19491949
} catch (java.io.UnsupportedEncodingException ex) {
19501950
throw new UnsupportedOperationException(ex);
19511951
}

src/main/java/com/github/underscore/Xml.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,8 +1515,9 @@ private static String unescapeName(final String name) {
15151515
StringBuilder result = new StringBuilder();
15161516
int underlineCount = 0;
15171517
StringBuilder lastChars = new StringBuilder();
1518+
int i = 0;
15181519
outer:
1519-
for (int i = 0; i < length; ++i) {
1520+
while (i < length) {
15201521
char ch = name.charAt(i);
15211522
if (ch == '_') {
15221523
lastChars.append(ch);
@@ -1535,6 +1536,7 @@ private static String unescapeName(final String name) {
15351536
i = j;
15361537
underlineCount = 0;
15371538
lastChars.setLength(0);
1539+
i++;
15381540
continue outer;
15391541
}
15401542
} else {
@@ -1546,6 +1548,7 @@ private static String unescapeName(final String name) {
15461548
result.append(lastChars).append(ch);
15471549
lastChars.setLength(0);
15481550
}
1551+
i++;
15491552
}
15501553
return result.append(lastChars).toString();
15511554
}

0 commit comments

Comments
 (0)