mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
more memory-efficient implementation of line reading
This commit is contained in:
parent
12bcba01cd
commit
c78253fd93
6 changed files with 96 additions and 45 deletions
|
|
@ -321,18 +321,6 @@ func (list *Buffer) next(index int) int {
|
|||
}
|
||||
}
|
||||
|
||||
// return n such that v <= n and n == 2**i for some i
|
||||
func roundUpToPowerOfTwo(v int) int {
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html
|
||||
v -= 1
|
||||
v |= v >> 1
|
||||
v |= v >> 2
|
||||
v |= v >> 4
|
||||
v |= v >> 8
|
||||
v |= v >> 16
|
||||
return v + 1
|
||||
}
|
||||
|
||||
func (list *Buffer) maybeExpand() {
|
||||
if list.window == 0 {
|
||||
return // autoresize is disabled
|
||||
|
|
@ -352,7 +340,7 @@ func (list *Buffer) maybeExpand() {
|
|||
return // oldest element is old enough to overwrite
|
||||
}
|
||||
|
||||
newSize := roundUpToPowerOfTwo(length + 1)
|
||||
newSize := utils.RoundUpToPowerOfTwo(length + 1)
|
||||
if list.maximumSize < newSize {
|
||||
newSize = list.maximumSize
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue