[perf][queue] Replace %s with copy.

This avoids relatively expensive `%` operations and `copy` is much easier to optimize.
This commit is contained in:
Taras Tsugrii 2023-07-04 20:55:36 -05:00 committed by GitHub
parent e126572f8a
commit a3675d22c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -32,9 +32,9 @@ func (q *queue) grow() {
}
newElems := make([]any, newCap)
oldLen := q.len
for i := 0; i < oldLen; i++ {
newElems[i] = q.elems[(q.head+i)%oldCap]
}
copy(newElems, q.elems[q.head:])
wrote := oldLen - q.head
copy(newElems[wrote:], q.elems[:q.head])
q.elems = newElems
q.head = 0
}