Merge: lib/string: `Int::to_s` shortcuts 0 and 1
authorJean Privat <jean@pryen.org>
Wed, 18 Mar 2015 05:41:48 +0000 (12:41 +0700)
committerJean Privat <jean@pryen.org>
Wed, 18 Mar 2015 05:41:48 +0000 (12:41 +0700)
commitf53967a9d05aa4f6642896a02cdeaee33f36e7ea
tree173a35d2e6578870b2383ed335a3480c6e650362
parent1fc4c820aca6ff84e99be62fe08f41ba0f986270
parenta053bfd6535415d6589ff27eb9cbcc323792d62b
Merge: lib/string: `Int::to_s` shortcuts 0 and 1

Valgrid said it is used a lot.

So I mixed (`-m`) nitc with the following module

~~~nit
import counter

redef class Int
redef fun to_s
do
sys.itos_cpt.inc(self)
return super
end
end

redef class Sys
var itos_cpt = new Counter[Int]
redef fun run
do
super
itos_cpt.print_summary
itos_cpt.print_elements(10)
end
end
~~~

The result shows that `0` and `1` are the top `to_s`-ized numbers.

~~~
  0: 13554 (9.29%)
  1: 10012 (6.86%)
  2: 5671 (3.88%)
~~~

So I just shortcut-them to reduce allocations.

With nitc/nitc/nitc:
before: 0m6.756s
after: 0m6.632s (-2%)

Pull-Request: #1207
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>