mdedetrich / scalajson

ScalaJSON - JSON for Scala, currently contains minimal AST
BSD 3-Clause "New" or "Revised" License
55 stars 10 forks source link

Precompile `jNumberRegex` or move to manual verification #32

Closed sirthias closed 7 years ago

sirthias commented 7 years ago

Currently jNumberRegex is a simple String, which means that for every application of the regex, i.e. every creation of a JNumber instance from a String the regex has to be compiled before it is run.

IMHO the regex should be precompiled or, even better, turned into a manual check.

Of course one could also debate whether the check is really necessary at all, since JNumber instances will typically be created either by a parser or by one of the non-string JNumber.apply overloads, which will never created illegal number strings anyway.

mdedetrich commented 7 years ago

@sirthias Are you aware of a regex precompiler for Scala/Java?

EDIT: nvm, just noticed the compile method. Will have a look into this.

mdedetrich commented 7 years ago

Okay I have just pushed this, according to the Scala docs the .r method on Strings return a compiled regex