mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
98c38f2b1f
commit
79cdd2b252
@ -30,7 +30,8 @@ c11_vector c11_vector__copy(const c11_vector* self){
|
|||||||
void c11_vector__reserve(c11_vector* self, int capacity){
|
void c11_vector__reserve(c11_vector* self, int capacity){
|
||||||
if(capacity < 4) capacity = 4;
|
if(capacity < 4) capacity = 4;
|
||||||
if(capacity <= self->capacity) return;
|
if(capacity <= self->capacity) return;
|
||||||
self->data = realloc(self->data, self->elem_size * capacity);
|
// self->elem_size * capacity may overflow
|
||||||
|
self->data = realloc(self->data, self->elem_size * (size_t)capacity);
|
||||||
self->capacity = capacity;
|
self->capacity = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,3 +25,7 @@ def gen_data():
|
|||||||
for i in range(100):
|
for i in range(100):
|
||||||
ratio = test(gen_data())
|
ratio = test(gen_data())
|
||||||
# print(f'compression ratio: {ratio:.2f}')
|
# print(f'compression ratio: {ratio:.2f}')
|
||||||
|
|
||||||
|
# test 100MB of random data
|
||||||
|
rnd = [random.randint(0, 255) for _ in range(1024*1024*100)]
|
||||||
|
test(bytes(rnd))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user