Merge: Clean UTF-8 string update
authorJean Privat <jean@pryen.org>
Tue, 15 Sep 2015 16:57:16 +0000 (12:57 -0400)
committerJean Privat <jean@pryen.org>
Tue, 15 Sep 2015 16:57:16 +0000 (12:57 -0400)
commit827c9eae6ce5afff368c39d97d0bc8b95007c16c
tree2f462952d41e746c17d7248d38c577ce1adb4623
parent2b0983a52aa3cc6d98e0c0f4b3b6ab0509cdb944
parent2a731344f2c760b78d5144f92ab73890320ce37a
Merge: Clean UTF-8 string update

Since quite some time now we've had the cleaning function for Bytes that ensured that what was coming from the exterior was clean and could be transformed safely to a String.

This is now generalized to any NativeString, and the clean function will be called each time a NativeString is `to_s`'d

At the same time, `clean_utf8` is now better performing (for `Files::read_all`, Ir per call is roughly 40% less than before), which limits the impacts of the new strategy.

Furthermore, the string produced by `NativeString::clean_utf8` has its length calculated which saves time on later operations on the string.

It also limits the number of calls by avoiding allocations if not necessary (if the string is already clean, which should happen a lot more often than not).

As for performances,

Valgrind `./bin/nitc src/nitc.nit`:
Before: 14.040 GIr
After: 13.859 GIr

Time, best of 10 for `./bin/nitc src/nitc.nit -o bin/nitc`:
Before: 0m4.989s
After: 0m4.933s

Time, best of 10 for `./bin/nitc --semi-global src/nitc.nit -o bin/nitc`:
Before: 0m4.696s
After: 0m4.691s

Pretty much equivalent in real time, and a bit better in Valgrind, not bad considering every String is now cleaner than ever !

Pull-Request: #1705
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>