Let's not allocate iterate but use good old for loop

This commit is contained in:
serso 2016-01-08 16:35:27 +01:00
parent 637827d79d
commit 72654932f2

View File

@ -280,7 +280,7 @@ public enum MathType {
final StartsWithFinder startsWithFinder = new StartsWithFinder(text, i); final StartsWithFinder startsWithFinder = new StartsWithFinder(text, i);
for (MathType mathType : getMathTypesByPriority()) { for (MathType mathType : getMathTypesByPriority()) {
final String s = Collections.find(mathType.getTokens(), startsWithFinder); final String s = find(mathType.getTokens(), startsWithFinder);
if (s != null) { if (s != null) {
if (s.length() == 1) { if (s.length() == 1) {
if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) { if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) {
@ -297,6 +297,17 @@ public enum MathType {
return new Result(MathType.text, text.substring(i)); return new Result(MathType.text, text.substring(i));
} }
@Nullable
private static String find(@Nonnull List<String> list, @Nonnull JPredicate<String> predicate) {
for (int i = 0; i < list.size(); i++) {
final String token = list.get(i);
if(predicate.apply(token)) {
return token;
}
}
return null;
}
@Nonnull @Nonnull
private static List<MathType> getMathTypesByPriority() { private static List<MathType> getMathTypesByPriority() {
if (mathTypesByPriority == null) { if (mathTypesByPriority == null) {