Skip to content

Commit 2dfa3a8

Browse files
committed
move buffer growth to allocation instead of reset
1 parent 28c63e7 commit 2dfa3a8

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/implementation/allocator.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ function tensoralloc(
254254
offset = buffer.offset + allocation_size(T, structure)
255255
buffer.max_offset = max(buffer.max_offset, offset)
256256

257+
# grow buffer if empty
258+
isempty(buffer) && sizehint!(buffer, buffer.max_offset)
259+
257260
# Use pointer if there is enough space
258261
if offset < length(buffer)
259262
buffer.offset = offset
@@ -271,10 +274,5 @@ function allocator_reset!(buffer::BufferAllocator, checkpoint)
271274
checkpoint buffer.offset ||
272275
throw(ArgumentError("Invalid checkpoint: `allocator_reset!` has to be called in reverse order on saved checkpoints"))
273276
buffer.offset = checkpoint
274-
275-
# check for growth
276-
iszero(checkpoint) && (buffer.max_offset > length(buffer)) &&
277-
sizehint!(buffer, buffer.max_offset)
278-
279277
return buffer
280278
end

0 commit comments

Comments
 (0)