(bounds []arrayElementBounds, newEntryLen, maxTotalBytes int)
| 292 | } |
| 293 | |
| 294 | func getKeepStart(bounds []arrayElementBounds, newEntryLen, maxTotalBytes int) int { |
| 295 | if maxTotalBytes <= 0 { |
| 296 | return 0 |
| 297 | } |
| 298 | |
| 299 | // Keep newest entry even if it's larger than the configured cap. |
| 300 | newOnlyLen := 2 + newEntryLen // `[` + entry + `]` |
| 301 | if newOnlyLen > maxTotalBytes { |
| 302 | return len(bounds) |
| 303 | } |
| 304 | |
| 305 | if len(bounds) == 0 { |
| 306 | return 0 |
| 307 | } |
| 308 | |
| 309 | lastEnd := bounds[len(bounds)-1].End |
| 310 | |
| 311 | // Iterate from oldest to newest so we drop the minimum number of entries |
| 312 | // necessary to fit the configured cap. |
| 313 | for keepStart := 0; keepStart <= len(bounds); keepStart++ { |
| 314 | contentLen := newEntryLen |
| 315 | if keepStart < len(bounds) { |
| 316 | // Use actual byte offsets from parsed elements so separator |
| 317 | // whitespace is fully counted toward the cap. |
| 318 | keptContentLen := lastEnd - bounds[keepStart].Start |
| 319 | contentLen += 1 + keptContentLen // comma between kept suffix and new entry |
| 320 | } |
| 321 | totalLen := 2 + contentLen // `[` + content + `]` |
| 322 | if totalLen <= maxTotalBytes { |
| 323 | return keepStart |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return len(bounds) |
| 328 | } |
| 329 | |
| 330 | func buildAppendedArray(existingArrayBytes []byte, bounds []arrayElementBounds, keepStart int, newEntryBytes []byte) []byte { |
| 331 | totalLen := 0 |
no outgoing calls
no test coverage detected
searching dependent graphs…