readding inline to some stack.nim procs
This commit is contained in:
parent
856d1345e4
commit
70fa10bfa6
|
@ -3,4 +3,4 @@ var fib = proc(n)
|
||||||
else fib(n-1) + fib(n-2)
|
else fib(n-1) + fib(n-2)
|
||||||
;
|
;
|
||||||
|
|
||||||
print (fib(37));
|
print (fib(37));
|
||||||
|
|
|
@ -42,7 +42,7 @@ template high*[T](stack: Stack[T]): int =
|
||||||
template len*[T](stack: Stack[T]): int =
|
template len*[T](stack: Stack[T]): int =
|
||||||
stack.high() + 1
|
stack.high() + 1
|
||||||
|
|
||||||
proc push*[T](stack: var Stack[T], item: T) =
|
proc push*[T](stack: var Stack[T], item: T) {.inline.} =
|
||||||
let len = stack.len()
|
let len = stack.len()
|
||||||
if len == stack.cap:
|
if len == stack.cap:
|
||||||
stack.grow(len)
|
stack.grow(len)
|
||||||
|
@ -53,20 +53,20 @@ proc push*[T](stack: var Stack[T], item: T) =
|
||||||
template add*[T](stack: var Stack[T], item: T) =
|
template add*[T](stack: var Stack[T], item: T) =
|
||||||
stack.push(item)
|
stack.push(item)
|
||||||
|
|
||||||
proc pop*[T](stack: var Stack[T]): T =
|
proc pop*[T](stack: var Stack[T]): T {.inline.} =
|
||||||
when boundsChecks:
|
when boundsChecks:
|
||||||
if stack.top == nil or stack.top.pless(stack.start):
|
if stack.top == nil or stack.top.pless(stack.start):
|
||||||
raise newException(Defect, "Stacktop is nil or smaller than start.")
|
raise newException(Defect, "Stacktop is nil or smaller than start.")
|
||||||
result = stack.top[]
|
result = stack.top[]
|
||||||
stack.top = stack.top.psub(sizeof(T))
|
stack.top = stack.top.psub(sizeof(T))
|
||||||
|
|
||||||
proc peek*[T](stack: Stack[T]): var T =
|
proc peek*[T](stack: Stack[T]): var T {.inline.} =
|
||||||
when boundsChecks:
|
when boundsChecks:
|
||||||
if stack.top == nil or stack.top.pless(stack.start):
|
if stack.top == nil or stack.top.pless(stack.start):
|
||||||
raise newException(Defect, "Stacktop is nil or smaller than start.")
|
raise newException(Defect, "Stacktop is nil or smaller than start.")
|
||||||
stack.top[]
|
stack.top[]
|
||||||
|
|
||||||
proc settip*[T](stack: var Stack[T], newtip: T) =
|
proc settip*[T](stack: var Stack[T], newtip: T) {.inline.} =
|
||||||
when boundsChecks:
|
when boundsChecks:
|
||||||
if stack.top == nil or stack.top.pless(stack.start):
|
if stack.top == nil or stack.top.pless(stack.start):
|
||||||
raise newException(Defect, "Stacktop is nil or smaller than start")
|
raise newException(Defect, "Stacktop is nil or smaller than start")
|
||||||
|
@ -87,7 +87,7 @@ proc deleteTopN*[T](stack: var Stack[T], n: Natural) =
|
||||||
if stack.top.pless(stack.start):
|
if stack.top.pless(stack.start):
|
||||||
raise newException(Defect, "Stacktop sunk below the start after a deleteTopN.")
|
raise newException(Defect, "Stacktop sunk below the start after a deleteTopN.")
|
||||||
|
|
||||||
proc getIndex*[T](stack: Stack[T], index: int): var T =
|
proc getIndex*[T](stack: Stack[T], index: int): var T {.inline.} =
|
||||||
when boundsChecks:
|
when boundsChecks:
|
||||||
if index < 0 or index >= stack.len():
|
if index < 0 or index >= stack.len():
|
||||||
raise newException(Defect, &"Attempt to getIndex with an index {index} which is out of bounds (len: {stack.len()}).")
|
raise newException(Defect, &"Attempt to getIndex with an index {index} which is out of bounds (len: {stack.len()}).")
|
||||||
|
@ -102,7 +102,7 @@ proc getIndexNeg*[T](stack: Stack[T], index: int): var T =
|
||||||
template `[]`*[T](stack: Stack[T], index: int): var T =
|
template `[]`*[T](stack: Stack[T], index: int): var T =
|
||||||
stack.getIndex(index)
|
stack.getIndex(index)
|
||||||
|
|
||||||
proc setIndex*[T](stack: var Stack[T], index: int, item: T) =
|
proc setIndex*[T](stack: var Stack[T], index: int, item: T) {.inline.} =
|
||||||
when boundsChecks:
|
when boundsChecks:
|
||||||
if index < 0 or index >= stack.len():
|
if index < 0 or index >= stack.len():
|
||||||
raise newException(Defect, "Attempt to getIndex with an index out of bounds.")
|
raise newException(Defect, "Attempt to getIndex with an index out of bounds.")
|
||||||
|
|
Loading…
Reference in New Issue