From 90415d49c5ae1996353e9aeef0dc568ad61c688e Mon Sep 17 00:00:00 2001 From: Max Chechel Date: Tue, 23 Jan 2018 11:36:54 +0300 Subject: [PATCH] return buffer back to the pool --- migration_sql.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/migration_sql.go b/migration_sql.go index 8ea2c08..9f2ea69 100644 --- a/migration_sql.go +++ b/migration_sql.go @@ -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