Skip to content

Commit

Permalink
Using compiled patterns in StatementBuilder to improve rendering perf…
Browse files Browse the repository at this point in the history
…ormance
  • Loading branch information
JoshIsOnIt authored and csadilek committed Mar 13, 2015
1 parent df935ad commit f684856
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -16,6 +16,9 @@

package org.jboss.errai.codegen.builder.impl;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jboss.errai.codegen.BooleanExpression;
import org.jboss.errai.codegen.Cast;
import org.jboss.errai.codegen.Comment;
Expand Down Expand Up @@ -62,12 +65,16 @@
*/
public class StatementBuilder extends AbstractStatementBuilder implements StatementBegin {

private static final Pattern THIS_OR_SUPPER_PATTERN = Pattern.compile("(this|super)");
private static final Pattern THIS_PATTERN = Pattern.compile("(this.)(.)*");

public StatementBuilder(final Context context) {
super(context);

if (context != null) {
for (final Variable v : context.getDeclaredVariables()) {
if (v.getName().matches("(this|super)")) continue;
Matcher m = THIS_OR_SUPPER_PATTERN.matcher(v.getName());
if(m.matches()) continue;
appendCallElement(new DeclareVariable(v));
}
appendCallElement(new ResetCallElement());
Expand Down Expand Up @@ -195,9 +202,10 @@ private StatementBuilder declareVariable(final Variable v) {

@Override
public VariableReferenceContextualStatementBuilder loadVariable(final String name, final Object... indexes) {
if (name.matches("(this.)(.)*"))
Matcher m = THIS_PATTERN.matcher(name);
if (m.matches()) {
return loadClassMember(name.replaceFirst("(this.)", ""), indexes);

}
appendCallElement(new LoadVariable(name, indexes));
return new ContextualStatementBuilderImpl(context, callElementBuilder);
}
Expand Down

0 comments on commit f684856

Please sign in to comment.