Skip to content

Commit

Permalink
Fix finding against null range value by including the full possible r…
Browse files Browse the repository at this point in the history
…ange, which might cover more nulls.
  • Loading branch information
broneill committed Sep 5, 2024
1 parent b9db8ce commit 417a7f2
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/main/java/org/cojen/tupl/table/expr/WindowBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,7 @@ private static void makeFindRangeLoop(Type type, MethodMaker mm,
Label loopEnd = mm.label();
indexVar.ifGe(endIndexVar, loopEnd);

var findVar = mm.invoke("get", indexVar.cast(int.class));
if (!findVar.classType().isPrimitive()) {
findVar.ifEq(null, done);
}
findVar = Arithmetic.eval(type, Token.T_PLUS, findVar, deltaVar);
var findVar = makeFindVar(type, indexVar, deltaVar);

Label doStart = mm.label().here();
indexVar.inc(1);
Expand Down Expand Up @@ -932,11 +928,7 @@ private static void makeFindRangeLoop(Type type, MethodMaker mm,
Label loopEnd = mm.label();
indexVar.ifLe(0, loopEnd);

var findVar = mm.invoke("get", indexVar.cast(int.class));
if (!findVar.classType().isPrimitive()) {
findVar.ifEq(null, done);
}
findVar = Arithmetic.eval(type, Token.T_PLUS, findVar, deltaVar);
var findVar = makeFindVar(type, indexVar, deltaVar);

Label doStart = mm.label().here();
indexVar.dec(1);
Expand Down Expand Up @@ -965,6 +957,22 @@ private static void makeFindRangeLoop(Type type, MethodMaker mm,
done.here();
}

private static Variable makeFindVar(Type type, Variable indexVar, Variable deltaVar) {
MethodMaker mm = indexVar.methodMaker();
var findVar = mm.invoke("get", indexVar.cast(int.class));

if (findVar.classType().isPrimitive()) {
findVar = Arithmetic.eval(type, Token.T_PLUS, findVar, deltaVar);
} else {
Label skip = mm.label();
findVar.ifEq(null, skip);
findVar.set(Arithmetic.eval(type, Token.T_PLUS, findVar, deltaVar));
skip.here();
}

return findVar;
}

private static void addNumericalMethods(ClassMaker cm, Type type) {
Class clazz = type.clazz();
Class unboxed = type.unboxedType();
Expand Down

0 comments on commit 417a7f2

Please sign in to comment.