Skip to content

Commit

Permalink
Qute: fix perf optimization in ReflectionValueResolver
Browse files Browse the repository at this point in the history
- fixes quarkusio#44797

(cherry picked from commit 06f4006)
  • Loading branch information
mkouba authored and gsmet committed Nov 30, 2024
1 parent a3b4042 commit 1a5fe71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public CompletionStage<Object> getValue(Object instance) {
public boolean isShared(EvalContext context) {
if (methods.size() == 1) {
for (Expression param : context.getParams()) {
if (param.isLiteral()) {
if (!param.isLiteral()) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@ public void testStaticMembersIgnored() {
@Test
public void testCachedResolver() {
Template template = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).build()
.parse("{foo.name}");
Expression exp = template.findExpression(e -> e.toOriginalString().equals("foo.name"));
PartImpl part = (PartImpl) exp.getParts().get(1);
assertNull(part.cachedResolver);
assertEquals("box", template.data("foo", new Foo("box")).render());
assertNotNull(part.cachedResolver);
assertTrue(part.cachedResolver instanceof ReflectionValueResolver.AccessorResolver);
.parse("{foo.name}::{foo.name.repeat(5)}::{foo.name.repeat(n)}");
Expression fooName = template.findExpression(e -> e.toOriginalString().equals("foo.name"));
Expression fooNameRepeat5 = template.findExpression(e -> e.toOriginalString().equals("foo.name.repeat(5)"));
Expression fooNameRepeatN = template.findExpression(e -> e.toOriginalString().equals("foo.name.repeat(n)"));
PartImpl fooNamePart = (PartImpl) fooName.getParts().get(1);
PartImpl fooNameRepeat5Part = (PartImpl) fooNameRepeat5.getParts().get(2);
PartImpl fooNameRepeatNPart = (PartImpl) fooNameRepeatN.getParts().get(2);
assertNull(fooNamePart.cachedResolver);
assertNull(fooNameRepeat5Part.cachedResolver);
assertNull(fooNameRepeatNPart.cachedResolver);
assertEquals("box::boxboxboxboxbox::box", template.data("foo", new Foo("box"), "n", 1).render());
assertEquals("box::boxboxboxboxbox::boxbox", template.data("foo", new Foo("box"), "n", 2).render());
assertNotNull(fooNamePart.cachedResolver);
assertNotNull(fooNameRepeat5Part.cachedResolver);
assertNotNull(fooNameRepeatNPart.cachedResolver);
assertTrue(fooNamePart.cachedResolver instanceof ReflectionValueResolver.AccessorResolver);
assertTrue(fooNameRepeat5Part.cachedResolver instanceof ReflectionValueResolver.AccessorResolver);
assertTrue(fooNameRepeatNPart.cachedResolver instanceof ReflectionValueResolver.CandidateResolver);
}

public static class Foo {
Expand Down

0 comments on commit 1a5fe71

Please sign in to comment.