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