Merge: lib/standard: optimize Array.to_s
authorJean Privat <jean@pryen.org>
Tue, 26 Aug 2014 22:56:25 +0000 (18:56 -0400)
committerJean Privat <jean@pryen.org>
Tue, 26 Aug 2014 22:56:25 +0000 (18:56 -0400)
Micro-optimized version of Array::to_s based on the results of benchmarks available in PR #685.

`./bin/nitg ./src/nitg.nit`
Before : `15.080 s`
After : `13.928 s`

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

1  2 
lib/standard/collection/array.nit
tests/sav/test_new_native_alt1.res

@@@ -186,19 -186,6 +186,19 @@@ abstract class AbstractArray[E
                self[pos] = item
        end
  
 +      redef fun insert_all(coll, pos)
 +      do
 +              var l = coll.length
 +              if l == 0 then return
 +              enlarge(length + l)
 +              _length += l
 +              copy_to(pos, length-pos-l, self, pos + l)
 +              for c in coll do
 +                      self[pos] = c
 +                      pos += 1
 +              end
 +      end
 +
        redef fun add(item) do self[length] = item
  
        redef fun clear do _length = 0
@@@ -745,6 -732,8 +745,8 @@@ en
  # Access are unchecked and it has a fixed size
  # Not for public use: may become private.
  universal NativeArray[E]
+       # Creates a new NativeArray of capacity `length`
+       new(length: Int) is intern
        # The length of the array
        fun length: Int is intern
        # Use `self` to initialize a standard Nit Array.
@@@ -1,4 -1,4 +1,4 @@@
- Runtime error: Cast failed. Expected `NativeArray#0`, got `Bool` (../lib/standard/collection/array.nit:753)
 -Runtime error: Cast failed. Expected `NativeArray#0`, got `Bool` (../lib/standard/collection/array.nit:742)
++Runtime error: Cast failed. Expected `NativeArray#0`, got `Bool` (../lib/standard/collection/array.nit:755)
  NativeString
  N
  Nit