MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / Reset

Method Reset

pkg/sql/tokenizer/pool.go:161–188  ·  view source on GitHub ↗

Reset clears a Tokenizer's state for reuse while preserving allocated memory. This method is called automatically by PutTokenizer() and generally should not be called directly by users. It's exposed for advanced use cases where you want to reuse a tokenizer instance without going through the pool.

()

Source from the content-addressed store, hash-verified

159// Performance: By preserving slice capacity, subsequent Tokenize() calls
160// avoid reallocation of lineStarts for similarly-sized inputs.
161func (t *Tokenizer) Reset() {
162 // Clear input reference to allow garbage collection
163 t.input = nil
164
165 // Reset position tracking
166 t.pos = NewPosition(1, 0)
167 t.lineStart = Position{}
168
169 // Preserve lineStarts slice capacity but reset length
170 if cap(t.lineStarts) > 0 {
171 t.lineStarts = t.lineStarts[:0]
172 t.lineStarts = append(t.lineStarts, 0)
173 } else {
174 // Initialize if not yet allocated
175 t.lineStarts = make([]int, 1, 16) // Start with reasonable capacity
176 t.lineStarts[0] = 0
177 }
178
179 t.line = 0
180
181 // Don't reset keywords as they're constant
182 t.logger = nil
183
184 // Preserve Comments slice capacity but reset length
185 if cap(t.Comments) > 0 {
186 t.Comments = t.Comments[:0]
187 }
188}

Callers 5

TokenizeMethod · 0.95
TokenizeContextMethod · 0.95
putBufferFunction · 0.45
PutTokenizerFunction · 0.45
TestTokenizer_ResetFunction · 0.45

Calls 1

NewPositionFunction · 0.85

Tested by 1

TestTokenizer_ResetFunction · 0.36