I rewrote trrename, but it's much slower
I rewrote trrename to use raw xpath and tree edits in this commit. but the renaming process is much much slower. It's likely I will need to go back to the old way (parse, replace the raw string and reparse the entire tree).
I think the problem is that the Antlr trees it not a good representation for editing. Consider what is done with each rename:
- Use xpath to find all elements in the tree that correspond to a defining or applied occurrence of an identifier. This should be fairly quick.
- For each node to rename:
- Insert the new text in the charstream buffer.
- Insert a new token in the tokstream.
- Update the token stream with new start, stop charstream locations.
- Update the parse tree with new token intervals.
- Delete the old text in char stream buffer
- Delete the old token in tok stream.
- Update the token stream with new start, stop charstream locations.
- Update the parse tree with new token intervals.
The problem with all this is that the data structures are not optimized for simple editing. The token stream interval up the tree is not terribly useful. I can't really see many times I would ever use it (trtext), so why isn't just computed on demand?
Notes: Trash precomputes the parse tree "SourceIntervals" after parsing, and maintains it throughout all tools. Antlr itself doesn't compute the interval on demand, relying on _start and _stop to be set at some point in time for the whole tree (see this code). => I think I didn't define the definition of SourceInterval correctly. It should be computed on the fly.