added system.@ for openarrays

This commit is contained in:
Araq 2012-07-14 14:44:54 +02:00
commit d2872748c2
3 changed files with 11 additions and 8 deletions

View file

@ -1339,6 +1339,13 @@ proc isNil*(x: cstring): bool {.noSideEffect, magic: "IsNil".}
## Fast check whether `x` is nil. This is sometimes more efficient than ## Fast check whether `x` is nil. This is sometimes more efficient than
## ``== nil``. ## ``== nil``.
proc `@`*[T](a: openArray[T]): seq[T] =
## turns an openarray into a sequence. This is not as efficient as turning
## a fixed length array into a sequence as it always copies every element
## of `a`.
newSeq(result, a.len)
for i in 0..a.len-1: result[i] = a[i]
proc `&` *[T](x, y: seq[T]): seq[T] {.noSideEffect.} = proc `&` *[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
newSeq(result, x.len + y.len) newSeq(result, x.len + y.len)
for i in 0..x.len-1: for i in 0..x.len-1:

View file

@ -90,13 +90,6 @@ Library
- pdcurses bindings - pdcurses bindings
- for system:
proc `@` [T](a: openArray[T]): seq[T] =
newSeq(result, a.len)
for i in 0..a.len-1: result[i] = a[i]
--> ensure @[] still calls the array version!
Low priority Low priority
------------ ------------

View file

@ -59,6 +59,9 @@ Library Additions
- The httpclient module now supports ssl/tls. - The httpclient module now supports ssl/tls.
- Added ``times.format`` as well as many other utility functions - Added ``times.format`` as well as many other utility functions
for managing time. for managing time.
- Added ``system.@`` for converting an ``openarray`` to a ``seq`` (it used to
only support fixed length arrays).
Changes affecting backwards compatibility Changes affecting backwards compatibility
----------------------------------------- -----------------------------------------