summaryrefslogtreecommitdiffstats
path: root/src/reader.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-04-14 07:52:42 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-04-14 11:48:44 +0900
commite86b81bbf5c55344f4e29060b71eb1ab563296fe (patch)
treef062615f53a9e17e284d0170631e377528aa1dc2 /src/reader.go
parenta5447b8b7531dacb49961d3fccc404f634f06709 (diff)
Improve search performance by limiting the search scope
Find the last occurrence of the last character in the pattern and perform the search algorithm only up to that point. The effectiveness of this mechanism depends a lot on the shape of the input and the pattern.
Diffstat (limited to 'src/reader.go')
-rw-r--r--src/reader.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/reader.go b/src/reader.go
index fc9b4edb..a7e002c0 100644
--- a/src/reader.go
+++ b/src/reader.go
@@ -173,6 +173,12 @@ func (r *Reader) feed(src io.Reader) {
}
} else {
// Could not find the delimiter in the buffer
+ // NOTE: We can further optimize this by keeping track of the cursor
+ // position in the slab so that a straddling item that doesn't go
+ // beyond the boundary of a slab doesn't need to be copied to
+ // another buffer. However, the performance gain is negligible in
+ // practice (< 0.1%) and is not
+ // worth the added complexity.
leftover = append(leftover, buf...)
break
}