Merge: Faster ASCII-only strings
authorJean Privat <jean@pryen.org>
Thu, 28 Apr 2016 23:04:49 +0000 (19:04 -0400)
committerJean Privat <jean@pryen.org>
Thu, 28 Apr 2016 23:04:49 +0000 (19:04 -0400)
This simple PR re-introduces the concept of ASCII strings for faster no-overhead accesses to random characters in a string.

The class is private as it is to be used only internally, no client should care for the specific type of a String and all performance improvements will be automatic, should the optimization be possible.

Since we are dealing with UTF-8, the only case where O(1) access can efficiently and without much overhead (one `if` statement at creation) be determined, is when a string only contains ASCII characters.
Note that since the Buffer can change access semantics depending on what is appended during its lifetime, no ASCII-only FlatBuffer has been added.

This is implemented here by introducing two subclasses of FlatString, one for ASCII only strings, and one for regular Unicode strings (the old FlatString).

In terms of performance, in the compiler, there is a ~0.5% improvement, but in specific cases like JSON parsing for the `big_gov_data.json` (where not a single unicode character is present) bench, the difference amounts to ~35%.

Pull-Request: #2040
Reviewed-by: Jean Privat <jean@pryen.org>

1  2 
lib/json/serialization.nit

Simple merge