Improve TokenUtils performance through caching

For #9717.

For testing, you can take https://gist.github.com/MarcelGerber/5c11f1031af292044708, placing your cursor in the script tags and pressing `Ctrl-Space`.
I think it might be worth it for the future to have a Token class, with move methods and an internal cache, since it looks like after having a context we want to move it searching for something.