refactor getInput and move on
This commit is contained in:
parent
c8e0984370
commit
cfcc6227d1
|
@ -575,7 +575,7 @@ template mutatorImpl*(target, mutator, typ: untyped) =
|
|||
buffer: seq[byte] = @[0xf1'u8]
|
||||
cached: typ
|
||||
|
||||
proc getInput(x: var typ; data: openArray[byte]): var typ {.nocov, nosan.} =
|
||||
proc getInput(x: var typ; data: openArray[byte]): lent typ {.nocov, nosan.} =
|
||||
if equals(data, buffer):
|
||||
result = cached
|
||||
else:
|
||||
|
@ -583,6 +583,13 @@ template mutatorImpl*(target, mutator, typ: untyped) =
|
|||
fromData(data, pos, x)
|
||||
result = x
|
||||
|
||||
proc mgetInput(x: var typ; data: openArray[byte]) =
|
||||
if equals(data, buffer):
|
||||
x = move cached
|
||||
else:
|
||||
var pos = 1
|
||||
fromData(data, pos, x)
|
||||
|
||||
proc setInput(x: var typ; data: openArray[byte]; len: int) {.inline.} =
|
||||
setLen(buffer, len)
|
||||
var pos = 1
|
||||
|
@ -604,10 +611,11 @@ template mutatorImpl*(target, mutator, typ: untyped) =
|
|||
var x: typ
|
||||
if data.len > 1:
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 7, 1):
|
||||
x = move getInput(x, data)
|
||||
mgetInput(x, data)
|
||||
else:
|
||||
x = getInput(x, data)
|
||||
else: x = default(typeof(x))
|
||||
else:
|
||||
x = default(typeof(x))
|
||||
FuzzMutator(mutator)(x, maxLen-x.byteSize, r)
|
||||
result = x.byteSize+1 # +1 for the skipped byte
|
||||
if result <= maxLen:
|
||||
|
|
|
@ -49,12 +49,6 @@ import drchaos
|
|||
proc default[M, N: static[int]](_: typedesc[Matrix32[M, N]]): Matrix32[M, N] =
|
||||
zeros(M, N, float32)
|
||||
|
||||
#proc default(_: typedesc[OrderType]): OrderType =
|
||||
#colMajor
|
||||
|
||||
#proc default[M, N: static[int]](_: typedesc[ref array[N * M, float32]]): ref array[N * M, float32] =
|
||||
#new result
|
||||
|
||||
func fuzzTarget(x: Matrix32[2, 2]) =
|
||||
doAssert x != eye(2, float32)
|
||||
|
||||
|
|
Loading…
Reference in New Issue