return buffer back to the pool

pull/93/head
Max Chechel 2018-01-23 11:36:54 +03:00
parent 111f7d20fe
commit 90415d49c5
1 changed files with 7 additions and 2 deletions

View File

@ -23,10 +23,12 @@ var bufferPool = sync.Pool{
// Checks the line to see if the line has a statement-ending semicolon
// or if the line contains a double-dash comment.
func endsWithSemicolon(line string) bool {
scanBuf := bufferPool.Get().([]byte)
defer bufferPool.Put(scanBuf)
prev := ""
scanner := bufio.NewScanner(strings.NewReader(line))
scanner.Buffer(bufferPool.Get().([]byte), scanBufSize)
scanner.Buffer(scanBuf, scanBufSize)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
@ -51,8 +53,11 @@ func endsWithSemicolon(line string) bool {
// tell us to ignore semicolons.
func getSQLStatements(r io.Reader, direction bool) (stmts []string, tx bool) {
var buf bytes.Buffer
scanBuf := bufferPool.Get().([]byte)
defer bufferPool.Put(scanBuf)
scanner := bufio.NewScanner(r)
scanner.Buffer(bufferPool.Get().([]byte), scanBufSize)
scanner.Buffer(scanBuf, scanBufSize)
// track the count of each section
// so we can diagnose scripts with no annotations