Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling regular expressions for google-code-prettify

We are working on an extension to google-code-prettify which does the code-coloring for source-code on a webpage. We have a very long list of keywords (approx 4000) in Mathematica and while the performance is still very good, I wondered whether I can speed things up.

The regular expression for our keyword list looks like this

var keywords = 'AbelianGroup|Abort|AbortKernels|AbortProtect|Above|Abs|Absolute|\
AbsoluteCurrentValue|AbsoluteDashing|AbsoluteFileName|AbsoluteOptions|\
AbsolutePointSize|AbsoluteThickness|AbsoluteTime|AbsoluteTiming|AccountingForm';
new RegExp('^(?:' + keywords + ')\\b')

Can such an or-ed regex be made faster when it is compiled? Would it in the first place make sense to compile it, since google-code-prettify is a JavaScript running on the server. I don't know whether this script is loaded freshly every time a web-page is loaded. In this case, it is maybe not worth the overhead to compile it.

like image 739
halirutan Avatar asked Jun 19 '26 05:06

halirutan


1 Answers

  1. google-code-prettify runs on the client (it's a script; the source is requested from the server by the browser).
  2. Creating the RegExp object does compile it, at runtime.

In other words, just leave it as-is.

like image 141
Amber Avatar answered Jun 20 '26 18:06

Amber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!