Skip to content
Browse files

Merge branch 'jruby' of github.com:spullara/mustache.java into jruby

  • Loading branch information...
2 parents d1d398b + e213ff8 commit 6051318a83a33e6621bc879f10674a70e955d066 Sam Pullara committed Apr 16, 2012
View
17 compiler/src/main/java/com/github/mustachejava/jruby/JRubyObjectHandler.java
@@ -35,7 +35,7 @@ public Object coerce(Object object) {
}
@Override
- protected Wrapper findWrapper(final int scopeIndex, Wrapper[] wrappers, List<Predicate<Object[]>> guards, Object scope, String name) {
+ protected Wrapper findWrapper(final int scopeIndex, final Wrapper[] wrappers, final List<Predicate<Object[]>> guards, final Object scope, final String name) {
Wrapper wrapper = super.findWrapper(scopeIndex, wrappers, guards, scope, name);
if (wrapper == null) {
if (scope instanceof RubyHash) {
@@ -55,7 +55,22 @@ public boolean apply(@Nullable Object[] input) {
if (scope instanceof RubyObject) {
RubyObject ro = (RubyObject) scope;
if (ro.respondsTo(name)) {
+ guards.add(new Predicate<Object[]>() {
+ @Override
+ public boolean apply(@Nullable Object[] objects) {
+ RubyObject scope = (RubyObject) objects[scopeIndex];
+ return scope.respondsTo(name);
+ }
+ });
return createWrapper(scopeIndex, wrappers, guards, CALL_METHOD, new Object[]{ name });
+ } else {
+ guards.add(new Predicate<Object[]>() {
+ @Override
+ public boolean apply(@Nullable Object[] objects) {
+ RubyObject scope = (RubyObject) objects[scopeIndex];
+ return !scope.respondsTo(name);
+ }
+ });
}
}
}
View
16 compiler/src/test/java/com/github/mustachejavabenchmarks/JRubyBenchmarkTest.java
@@ -55,7 +55,21 @@ public void testComplexBench() throws MustacheException, IOException {
total++;
if (System.currentTimeMillis() - start > TIME) break;
}
- System.out.println("Serial: " + total / TIME);
+ System.out.println("Ruby: " + total / TIME);
+ }
+ {
+ DefaultMustacheFactory cf = new DefaultMustacheFactory();
+ Mustache m = cf.compile("complex.html");
+ Object context = new ComplexObject();
+ assertEquals(getContents(root, "complex.txt"), complextest(m, context).toString());
+ long start = System.currentTimeMillis();
+ int total = 0;
+ while (true) {
+ complextest(m, context);
+ total++;
+ if (System.currentTimeMillis() - start > TIME) break;
+ }
+ System.out.println("Java: " + total / TIME);
}
}
}

0 comments on commit 6051318

Please sign in to comment.
Something went wrong with that request. Please try again.