From 46fe948f5a7985749ea26d32035863d9c30959a8 Mon Sep 17 00:00:00 2001 From: Konstantin Voykov Date: Tue, 20 Feb 2024 23:38:39 +0200 Subject: [PATCH] Use raw (unsafe) memory clear on reset. --- go.mod | 1 + go.sum | 2 ++ vector.go | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 6849a85..98eee46 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/koykov/byteptr v1.0.0 github.com/koykov/fastconv v1.0.2 github.com/koykov/indirect v1.0.0 + github.com/koykov/openrt v0.0.0-20240220213454-7b5b4e8c30a5 ) require github.com/koykov/byteseq v0.0.0-20230330194259-68973f3b765a // indirect diff --git a/go.sum b/go.sum index 9ac9ae9..36aed86 100644 --- a/go.sum +++ b/go.sum @@ -10,3 +10,5 @@ github.com/koykov/fastconv v1.0.2 h1:csOWpctD9OcpkfI07LEtqtolc4TT8Y6QG3zQvkTmhrQ github.com/koykov/fastconv v1.0.2/go.mod h1:9jOx5KRGe4UKHxGiDw5Yrp/qrqn2cRwH3xvFjqqCE3c= github.com/koykov/indirect v1.0.0 h1:3kog1xvVUEB2142K2/AZRhnOKN2N8KNahHHkE+KT7ec= github.com/koykov/indirect v1.0.0/go.mod h1:2qWC0hrIHIexlKaqPA0VWEa0s2V/qxxNJv7XPncnh2I= +github.com/koykov/openrt v0.0.0-20240220213454-7b5b4e8c30a5 h1:Gf4EYzitGI5RjjRKT2fhYJcGuo9g6HRM4jvCO4KmmlA= +github.com/koykov/openrt v0.0.0-20240220213454-7b5b4e8c30a5/go.mod h1:y8Xa99HTBmthCilUUW36IZJd5SP9Rb+W8S9CJaauyU8= diff --git a/vector.go b/vector.go index 3f09b48..8212541 100644 --- a/vector.go +++ b/vector.go @@ -8,6 +8,7 @@ import ( "github.com/koykov/bitset" "github.com/koykov/bytealg" + "github.com/koykov/openrt" ) // Vector parser object. @@ -240,7 +241,7 @@ func (vec *Vector) getNode(depth int) (node *Node, idx int) { if vec.nodeL < n { _ = vec.nodes[n-1] node = &vec.nodes[vec.nodeL] - node.Reset() + // node.Reset() } else { vec.nodes = append(vec.nodes, Node{typ: TypeUnk}) n++ @@ -279,7 +280,9 @@ func (vec *Vector) Reset() { if vec.nodeL == 0 { return } - _ = vec.nodes[vec.nodeL-1] + openrt.MemclrUnsafe(unsafe.Pointer(&vec.nodes[0]), vec.nodeL*nodeSize) + vec.nodeL = 0 + vec.buf, vec.src = vec.buf[:0], nil vec.bufSS = vec.bufSS[:0] vec.addr, vec.nodeL, vec.errOff = 0, 0, 0