skip bounds checking in danger mode
This commit is contained in:
parent
7301597789
commit
29e3e70712
@ -26,24 +26,28 @@ proc `$`*(s: FixedSeq): string =
|
||||
|
||||
|
||||
proc `[]`*(s: FixedSeq, i: Natural): FixedSeq.Contents =
|
||||
when not defined(danger):
|
||||
if i > s.last:
|
||||
raise newException(IndexDefect, "index " & $i & " is out of bounds.")
|
||||
s.data[i]
|
||||
|
||||
|
||||
proc `[]`*(s: var FixedSeq, i: Natural): var FixedSeq.Contents =
|
||||
when not defined(danger):
|
||||
if i > s.last:
|
||||
raise newException(IndexDefect, "index " & $i & " is out of bounds.")
|
||||
s.data[i]
|
||||
|
||||
|
||||
proc `[]`*(s: FixedSeq, i: BackwardsIndex): auto =
|
||||
when not defined(danger):
|
||||
if s.last == -1:
|
||||
raise newException(IndexDefect, "index out of bounds, the container is empty.") # matching stdlib again
|
||||
s.data[s.last - typeof(s.last)(i) + 1]
|
||||
|
||||
|
||||
proc `[]=`*(s: var FixedSeq, i: Natural, v: FixedSeq.Contents) =
|
||||
when not defined(danger):
|
||||
if i > s.last:
|
||||
raise newException(IndexDefect, "index " & $i & " is out of bounds.")
|
||||
s.data[i] = v
|
||||
@ -94,6 +98,7 @@ proc insert*(s: var FixedSeq, v: FixedSeq.Contents, idx: Natural = 0) =
|
||||
|
||||
|
||||
proc delete*(s: var FixedSeq, idx: Natural) =
|
||||
when not defined(danger):
|
||||
if idx > s.last:
|
||||
raise newException(IndexDefect, "index " & $idx & " is out of bounds.")
|
||||
s.data[idx] = -1
|
||||
|
Loading…
x
Reference in New Issue
Block a user