MCPcopy Index your code
hub / github.com/riverqueue/river / buildAppendedArray

Function buildAppendedArray

riverlog/river_log.go:330–360  ·  view source on GitHub ↗
(existingArrayBytes []byte, bounds []arrayElementBounds, keepStart int, newEntryBytes []byte)

Source from the content-addressed store, hash-verified

328}
329
330func buildAppendedArray(existingArrayBytes []byte, bounds []arrayElementBounds, keepStart int, newEntryBytes []byte) []byte {
331 totalLen := 0
332 maxInt := int(^uint(0) >> 1)
333
334 // Preallocation is an optimization only. If length math would overflow,
335 // fall back to zero-capacity and let append grow as needed.
336 if keepStart >= len(bounds) {
337 if len(newEntryBytes) <= maxInt-2 {
338 totalLen = 2 + len(newEntryBytes)
339 }
340 } else {
341 // Kept suffix is contiguous in the original array bytes, so copy once.
342 keptContentLen := bounds[len(bounds)-1].End - bounds[keepStart].Start
343 if keptContentLen >= 0 && len(newEntryBytes) <= maxInt-3 && keptContentLen <= maxInt-3-len(newEntryBytes) {
344 totalLen = 3 + keptContentLen + len(newEntryBytes) // [] + comma + new entry
345 }
346 }
347
348 result := make([]byte, 0, totalLen)
349 result = append(result, '[')
350
351 if keepStart < len(bounds) {
352 result = append(result, existingArrayBytes[bounds[keepStart].Start:bounds[len(bounds)-1].End]...)
353 result = append(result, ',')
354 }
355
356 result = append(result, newEntryBytes...)
357 result = append(result, ']')
358
359 return result
360}

Callers 1

appendLogDataWithCapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…