Skip to content

Commit 4727f8d

Browse files
committed
feat(array): newPyArrayOfCap; breaks(array,list): new* inline
1 parent 1a712c8 commit 4727f8d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/pylib/Lib/array.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ func `@`*[T](arr: PyArray[T]): seq[T]{.inline.} = @(PyList[T](arr))
5858
5959
template itemsize*[T](arr: PyArray[T]): int = sizeof(T)
6060
61-
func newPyArray*[T](len=0): PyArray[T] = PyArray[T] newPyList[T](len)
61+
func newPyArray*[T](len=0): PyArray[T]{.inline.} = PyArray[T] newPyList[T](len)
6262
func newPyArray*[T](x: Iterable[T]): PyArray[T]{.inline.} =
6363
## unlike `array`_, when `x` is a literal, type conversion is always needed.
6464
runnableExamples:
6565
discard newPyArray[cint]([1.cint, 2])
6666
# or write: array('i', [1, 2])
6767
PyArray[T] list[T](x)
6868
69+
func newPyArrayOfCap*[T](cap: int): PyArray[T]{.inline.} =
70+
PyArray[T] newPyListOfCap[T](cap)
71+
6972
func fromlist*[T](arr: var PyArray[T], ls: PyList[T]) =
7073
arr.extend ls
7174

src/pylib/builtins/list_decl.nim

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ func repr*[T: set|string|openArray](self: PyList[T]): string =
2222
system.repr self.data.toOpenArray(0, len(self)-1)
2323
# `repr` defined for other elements' type is in about L160
2424
25-
func newPyList*[T](s: seq[T]): PyList[T] =
26-
result = PyList[T](data: s)
27-
func newPyList*[T](a: openArray[T]): PyList[T] =
28-
result = PyList[T](data: @a)
29-
func newPyList*[T](len=0): PyList[T] = newPyList newSeq[T](len)
30-
func newPyListOfCap*[T](cap=0): PyList[T] = newPyList newSeqOfCap[T](cap)
25+
func newPyList*[T](s: seq[T]): PyList[T]{.inline.} = PyList[T](data: s)
26+
func newPyList*[T](a: openArray[T]): PyList[T]{.inline.} = PyList[T](data: @a)
27+
func newPyList*[T](len=0): PyList[T]{.inline.} = newPyList newSeq[T](len)
28+
func newPyListOfCap*[T](cap=0): PyList[T]{.inline.} =
29+
newPyList newSeqOfCap[T](cap)
3130
3231
iterator items*[T](self: PyList[T]): T =
3332
for i in self.data: yield i

0 commit comments

Comments
 (0)