benchmarks/string: Updated bench scripts for strings
[nit.git] / benchmarks / strings / array_to_s_vars / array_to_s_rope.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 # Implementation of Array::to_s with a Rope exclusively
12 #
13 # To be used as a Mixin at compile-time for benchmarking purposes.
14 module array_to_s_rope
15
16 intrude import standard::collection::array
17 intrude import standard::ropes
18
19 redef class Array[E]
20
21 redef fun to_s do
22 var l = length
23 var it = _items
24 if l == 0 then return ""
25 if l == 1 then return it[0].to_s
26 var c = new Concat(it[0].to_s, it[1].to_s)
27 for i in [2 .. l[ do
28 c = new Concat(c, it[i].to_s)
29 end
30 return c
31 end
32
33 end