Skip to content

Commit a525a16

Browse files
committed
we're not using the sizes in the sidecar buffer so don't store them
1 parent ce2459a commit a525a16

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

stringdtype/stringdtype/src/static_string.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,18 @@ char *
109109
npy_string_arena_malloc(npy_string_arena *arena, npy_string_realloc_func r,
110110
size_t size)
111111
{
112-
// one extra size_t to store the size of the allocation
113-
size_t string_storage_size = size + sizeof(size_t);
114-
// expand size to nearest multiple of 8 bytes to ensure 64 bit alignment
115-
string_storage_size += (8 - string_storage_size % 8);
116-
if ((arena->size - arena->cursor) <= string_storage_size) {
112+
if ((arena->size - arena->cursor) <= size) {
117113
// realloc the buffer so there is enough room
118114
// first guess is to double the size of the buffer
119115
size_t newsize;
120116
if (arena->size == 0) {
121-
newsize = string_storage_size;
117+
newsize = size;
122118
}
123-
else if (((2 * arena->size) - arena->cursor) > string_storage_size) {
119+
else if (((2 * arena->size) - arena->cursor) > size) {
124120
newsize = 2 * arena->size;
125121
}
126122
else {
127-
newsize = arena->size + string_storage_size;
123+
newsize = arena->size + size;
128124
}
129125
if ((arena->cursor + size) >= newsize) {
130126
// doubling the current size isn't enough
@@ -139,10 +135,8 @@ npy_string_arena_malloc(npy_string_arena *arena, npy_string_realloc_func r,
139135
arena->buffer = newbuf;
140136
arena->size = newsize;
141137
}
142-
size_t *size_loc = (size_t *)&arena->buffer[arena->cursor];
143-
*size_loc = size;
144-
char *ret = &arena->buffer[arena->cursor + sizeof(size_t)];
145-
arena->cursor += string_storage_size;
138+
char *ret = &arena->buffer[arena->cursor];
139+
arena->cursor += size;
146140
return ret;
147141
}
148142

0 commit comments

Comments
 (0)