Skip to content

Commit

Permalink
Merge pull request google#39 from mikelalcon/optimiztion
Browse files Browse the repository at this point in the history
Restore Pattern.reset() method
  • Loading branch information
adonovan authored Nov 17, 2017
2 parents f6ab6e0 + 577c171 commit 7597ac7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions java/com/google/re2j/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public final class Pattern implements Serializable {
this.re2 = re2;
}

/**
* Releases current thread memory used by internal caches associated with this pattern. Does
* not change the observable behaviour. Useful for tests that detect memory
* leaks via allocation tracking.
*/
public void reset() {
re2.reset();
}

/**
* Returns the flags used in the constructor.
*/
Expand Down
5 changes: 5 additions & 0 deletions java/com/google/re2j/RE2.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ static RE2 compileImpl(String expr, int mode, boolean longest)
return re2;
}

// Clears the memory associated with this machine for the current thread.
void reset() {
machineThreadLocal.remove();
}

/**
* Returns the number of parenthesized subexpressions in this regular
* expression.
Expand Down

0 comments on commit 7597ac7

Please sign in to comment.