fn rebaseGrowing(mr: *MultiReader, context: *Context, capacity: usize) Allocator.Error!void mr: *MultiReadercontext: *Contextcapacity: usize243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269fn rebaseGrowing(mr: *MultiReader, context: *Context, capacity: usize) Allocator.Error!void {
const gpa = mr.gpa;
const r = &context.fr.interface;
if (r.buffer.len >= capacity) {
const data = r.buffer[r.seek..r.end];
@memmove(r.buffer[0..data.len], data);
r.seek = 0;
r.end = data.len;
} else {
const adjusted_capacity = std.ArrayList(u8).growCapacity(capacity);
if (r.seek == 0) {
if (gpa.remap(r.buffer, adjusted_capacity)) |new_memory| {
r.buffer = new_memory;
return;
}
}
const data = r.buffer[r.seek..r.end];
const new = try gpa.alloc(u8, adjusted_capacity);
@memcpy(new[0..data.len], data);
gpa.free(r.buffer);
r.buffer = new;
r.seek = 0;
r.end = data.len;
}
}