forked from jasder/antlr
Merge pull request #440 from sharwell/clone-token-text
Improve CommonToken cloning performance, and update documentation
This commit is contained in:
commit
de43cc427c
|
@ -139,10 +139,17 @@ public class CommonToken implements WritableToken, Serializable {
|
|||
/**
|
||||
* Constructs a new {@link CommonToken} as a copy of another {@link Token}.
|
||||
*
|
||||
* <p>
|
||||
* If {@code oldToken} is also a {@link CommonToken} instance, the newly
|
||||
* constructed token will share a reference to the {@link #text} field and
|
||||
* the {@link Pair} stored in {@link #source}. Otherwise, {@link #text} will
|
||||
* be assigned the result of calling {@link #getText}, and {@link #source}
|
||||
* will be constructed from the result of {@link Token#getTokenSource} and
|
||||
* {@link Token#getInputStream}.</p>
|
||||
*
|
||||
* @param oldToken The token to copy.
|
||||
*/
|
||||
public CommonToken(@NotNull Token oldToken) {
|
||||
text = oldToken.getText();
|
||||
type = oldToken.getType();
|
||||
line = oldToken.getLine();
|
||||
index = oldToken.getTokenIndex();
|
||||
|
@ -152,9 +159,11 @@ public class CommonToken implements WritableToken, Serializable {
|
|||
stop = oldToken.getStopIndex();
|
||||
|
||||
if (oldToken instanceof CommonToken) {
|
||||
text = ((CommonToken)oldToken).text;
|
||||
source = ((CommonToken)oldToken).source;
|
||||
}
|
||||
else {
|
||||
text = oldToken.getText();
|
||||
source = new Pair<TokenSource, CharStream>(oldToken.getTokenSource(), oldToken.getInputStream());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue