Split
A fast string and byte splitter for Go
Install / Use
/learn @clipperhouse/SplitREADME
A more efficient splitter for bytes and strings, with a focus on zero allocation, for Go. Use this where you would might use bytes.Split or strings.Split.
Usage
See pkg.go.dev
go get github.com/clipperhouse/split
import "github.com/clipperhouse/split"
text := "Hello, 世界. Nice dog! 👍🐶"
sep := " "
split := split.String(text, sep)
for split.Next() {
fmt.Println(split.Value())
}
Performance
Some initial benchmarks:
split.String (this package)
1185 ns/op 404.28 MB/s 0 B/op 0 allocs/op
strings.Split (standard library)
1267 ns/op 378.07 MB/s 1280 B/op 1 allocs/op
Overall, this package is a little faster, but more importantly, notice the difference in allocations. If you're on a hot path, this might add up, and reducing GC might help your app to scale.
Why you might use this
The standard library collects all the splits at once into an array, and allocates to do so (this is true in other languages as well).
This package lazily iterates over each split as needed, and avoids that allocation. Think of it as streaming instead of batching.
If you do not actually need the array, but only need to iterate over the splits, this package may be useful.
Data types
This packages handles string and []byte. If you have an io.Reader, we suggest bufio.Scanner from the standard library.
Testing
We work to ensure that split.Bytes and split.String offer an identical API and results as their standard library counterparts, bytes.Split and strings.Split. Have a look at the tests to verify that this is true.
Status
We've published a v0.1.0. Try it and leave feedback.
PR's are welcome, perhaps you'd like to implement a range iterator.
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
