Skip to content

Commit

Permalink
Avoid calling getChildCount in a loop to avoid n^2 behavior
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131070947
  • Loading branch information
concavelenz authored and brad4d committed Aug 23, 2016
1 parent fd32600 commit 8f3de51
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/com/google/javascript/refactoring/RefasterJsScanner.java
Expand Up @@ -140,7 +140,8 @@ public void clearTemplates() {
// If the template is a multiline template, make sure to delete the same number of sibling nodes
// as the template has.
Node n = match.getNode().getNext();
for (int i = 1; i < matchedTemplate.beforeTemplate.getLastChild().getChildCount(); i++) {
int count = matchedTemplate.beforeTemplate.getLastChild().getChildCount();
for (int i = 1; i < count; i++) {
Preconditions.checkNotNull(
n, "Found mismatched sibling count between before template and matched node.\n"
+ "Template: %s\nMatch: %s",
Expand Down

0 comments on commit 8f3de51

Please sign in to comment.