mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Pre-allocate availableAllocations to prevent a re-size in release
PiperOrigin-RevId: 418022431
This commit is contained in:
parent
fe1ffdb959
commit
6ee7cdf968
1 changed files with 6 additions and 6 deletions
|
|
@ -104,6 +104,12 @@ public final class DefaultAllocator implements Allocator {
|
|||
availableAllocations[availableCount] = null;
|
||||
} else {
|
||||
allocation = new Allocation(new byte[individualAllocationSize], 0);
|
||||
if (allocatedCount > availableAllocations.length) {
|
||||
// Make availableAllocations be large enough to contain all allocations made by this
|
||||
// allocator so that release() does not need to grow the availableAllocations array. See
|
||||
// [Internal ref: b/209801945].
|
||||
availableAllocations = Arrays.copyOf(availableAllocations, availableAllocations.length * 2);
|
||||
}
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
|
@ -116,12 +122,6 @@ public final class DefaultAllocator implements Allocator {
|
|||
|
||||
@Override
|
||||
public synchronized void release(Allocation[] allocations) {
|
||||
if (availableCount + allocations.length >= availableAllocations.length) {
|
||||
availableAllocations =
|
||||
Arrays.copyOf(
|
||||
availableAllocations,
|
||||
max(availableAllocations.length * 2, availableCount + allocations.length));
|
||||
}
|
||||
for (Allocation allocation : allocations) {
|
||||
availableAllocations[availableCount++] = allocation;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue