Skip to content
Permalink
Browse files
Lazily get keyword name from annotation.
The name was only used for exception messages, yet this method can be called multiple times per line, which was noticeable in profiling. This improves compile time around 6%.
  • Loading branch information
PseudoKnight committed Jun 16, 2020
1 parent d37f1a7 commit 7afbf9d80f27398feafc5669098f19d7d70c6d68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
@@ -21,7 +21,7 @@ public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompi
try {
if(list.get(keywordPosition).getData() instanceof CFunction) {
// It's a function, so do the old processing
SimpleBlockKeywordFunction.doProcess(this.getKeywordName(), null, true, list, keywordPosition);
SimpleBlockKeywordFunction.doProcess(this, null, true, list, keywordPosition);
// However, if we are proceeded by a ClassType, this is the return type of the closure, and it is
// easiest if we do the conversion here.
try {
@@ -21,7 +21,7 @@ public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompi
try {
if(list.get(keywordPosition).getData() instanceof CFunction) {
// It's a function, so do the old processing
SimpleBlockKeywordFunction.doProcess(this.getKeywordName(), null, true, list, keywordPosition);
SimpleBlockKeywordFunction.doProcess(this, null, true, list, keywordPosition);
// However, if we are proceeded by a ClassType, this is the return type of the closure, and it is
// easiest if we do the conversion here.
try {
@@ -17,7 +17,7 @@ public abstract class SimpleBlockKeywordFunction extends Keyword {
* This is the standalone version of the {@link #process(java.util.List, int)} function. All values must be passed
* in.
*
* @param keywordName The keyword name
* @param keyword The keyword
* @param functionArgumentCount The function clause argument count
* @param isStandaloneFunction Whether or not this is a standalone function (that is, it can be used without a block
* following it)
@@ -26,7 +26,7 @@ public abstract class SimpleBlockKeywordFunction extends Keyword {
* @return
* @throws ConfigCompileException
*/
public static int doProcess(String keywordName, Integer[] functionArgumentCount, boolean isStandaloneFunction, List<ParseTree> list, int keywordPosition) throws ConfigCompileException {
public static int doProcess(Keyword keyword, Integer[] functionArgumentCount, boolean isStandaloneFunction, List<ParseTree> list, int keywordPosition) throws ConfigCompileException {

Target t = list.get(keywordPosition).getTarget();
if(list.size() > keywordPosition + 1) {
@@ -43,10 +43,10 @@ public static int doProcess(String keywordName, Integer[] functionArgumentCount,
int firstClauseArgumentCount = list.get(keywordPosition).getChildren().size();
if(validArgs.length == 1) {
if(firstClauseArgumentCount != validArgs[0]) {
throw new ConfigCompileException("\"" + keywordName + "\" blocks "
throw new ConfigCompileException("\"" + keyword.getKeywordName() + "\" blocks "
+ (firstClauseArgumentCount > validArgs[0] ? "may only" : "must") + " have " + validArgs[0]
+ " argument" + (validArgs[0] == 1 ? "" : "s") + " passed to the"
+ " " + keywordName + " condition, " + firstClauseArgumentCount + " found.", t);
+ " " + keyword.getKeywordName() + " condition, " + firstClauseArgumentCount + " found.", t);
}
} else {
boolean error = true;
@@ -57,9 +57,9 @@ public static int doProcess(String keywordName, Integer[] functionArgumentCount,
}
}
if(error) {
throw new ConfigCompileException("\"" + keywordName + "\" blocks may not have " + firstClauseArgumentCount
+ " argument" + (firstClauseArgumentCount == 1 ? "" : "s") + " passed to the "
+ keywordName + " condition", t);
throw new ConfigCompileException("\"" + keyword.getKeywordName() + "\" blocks may not have "
+ firstClauseArgumentCount + " argument" + (firstClauseArgumentCount == 1 ? "" : "s")
+ " passed to the " + keyword.getKeywordName() + " condition", t);
}
}
}
@@ -68,15 +68,15 @@ public static int doProcess(String keywordName, Integer[] functionArgumentCount,
}
} else {
if(!isStandaloneFunction) {
throw new ConfigCompileException("Missing code block, following \"" + keywordName + "\"", t);
throw new ConfigCompileException("Missing code block, following \"" + keyword.getKeywordName() + "\"", t);
}
}
return keywordPosition;
}

@Override
public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompileException {
return doProcess(getKeywordName(), getFunctionArgumentCount(), isStandaloneFunction(), list, keywordPosition);
return doProcess(this, getFunctionArgumentCount(), isStandaloneFunction(), list, keywordPosition);
}

/**

0 comments on commit 7afbf9d

Please sign in to comment.