refactor getInput and move on

This commit is contained in:
Antonis Geralis 2022-09-05 19:27:37 +03:00
parent c8e0984370
commit cfcc6227d1
2 changed files with 11 additions and 9 deletions

View File

@ -575,7 +575,7 @@ template mutatorImpl*(target, mutator, typ: untyped) =
buffer: seq[byte] = @[0xf1'u8] buffer: seq[byte] = @[0xf1'u8]
cached: typ 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): if equals(data, buffer):
result = cached result = cached
else: else:
@ -583,6 +583,13 @@ template mutatorImpl*(target, mutator, typ: untyped) =
fromData(data, pos, x) fromData(data, pos, x)
result = 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.} = proc setInput(x: var typ; data: openArray[byte]; len: int) {.inline.} =
setLen(buffer, len) setLen(buffer, len)
var pos = 1 var pos = 1
@ -604,10 +611,11 @@ template mutatorImpl*(target, mutator, typ: untyped) =
var x: typ var x: typ
if data.len > 1: if data.len > 1:
when (NimMajor, NimMinor, NimPatch) >= (1, 7, 1): when (NimMajor, NimMinor, NimPatch) >= (1, 7, 1):
x = move getInput(x, data) mgetInput(x, data)
else: else:
x = getInput(x, data) x = getInput(x, data)
else: x = default(typeof(x)) else:
x = default(typeof(x))
FuzzMutator(mutator)(x, maxLen-x.byteSize, r) FuzzMutator(mutator)(x, maxLen-x.byteSize, r)
result = x.byteSize+1 # +1 for the skipped byte result = x.byteSize+1 # +1 for the skipped byte
if result <= maxLen: if result <= maxLen:

View File

@ -49,12 +49,6 @@ import drchaos
proc default[M, N: static[int]](_: typedesc[Matrix32[M, N]]): Matrix32[M, N] = proc default[M, N: static[int]](_: typedesc[Matrix32[M, N]]): Matrix32[M, N] =
zeros(M, N, float32) 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]) = func fuzzTarget(x: Matrix32[2, 2]) =
doAssert x != eye(2, float32) doAssert x != eye(2, float32)