-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07a417f
commit 978f9f3
Showing
5 changed files
with
52 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package mysql | ||
|
||
const defaultBufSize = 4096 | ||
|
||
// const maxCachedBufSize = 256 * 1024 | ||
|
||
type writeBuffer struct { | ||
buf []byte | ||
} | ||
|
||
// takeBuffer returns a buffer with the requested size. | ||
// If possible, a slice from the existing buffer is returned. | ||
// Otherwise a bigger buffer is made. | ||
// Only one buffer (total) can be used at a time. | ||
func (wb *writeBuffer) takeBuffer(length int) []byte { | ||
if length <= cap(wb.buf) { | ||
return wb.buf[:length] | ||
} | ||
if length <= defaultBufSize { | ||
wb.buf = make([]byte, length, defaultBufSize) | ||
return wb.buf | ||
} | ||
if length <= maxPacketSize { | ||
wb.buf = make([]byte, length) | ||
return wb.buf | ||
} | ||
return make([]byte, length) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters