mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Avoid double allocation in _bc_new_num_ex
Since the two allocations are tied together anyway, we can just use a single allocation. Moreover, this actually seemed like the intention because the bc_struct allocation already accounted for the length and scale.
This commit is contained in:
parent
f4dbe2390d
commit
3215e86a11
1 changed files with 2 additions and 7 deletions
|
@ -39,13 +39,12 @@
|
||||||
bc_num _bc_new_num_ex(size_t length, size_t scale, bool persistent)
|
bc_num _bc_new_num_ex(size_t length, size_t scale, bool persistent)
|
||||||
{
|
{
|
||||||
/* PHP Change: malloc() -> pemalloc(), removed free_list code */
|
/* PHP Change: malloc() -> pemalloc(), removed free_list code */
|
||||||
bc_num temp = (bc_num) safe_pemalloc(1, sizeof(bc_struct) + length, scale, persistent);
|
bc_num temp = safe_pemalloc(1, sizeof(bc_struct) + length, scale, persistent);
|
||||||
temp->n_sign = PLUS;
|
temp->n_sign = PLUS;
|
||||||
temp->n_len = length;
|
temp->n_len = length;
|
||||||
temp->n_scale = scale;
|
temp->n_scale = scale;
|
||||||
temp->n_refs = 1;
|
temp->n_refs = 1;
|
||||||
/* PHP Change: malloc() -> pemalloc() */
|
temp->n_ptr = (char *) temp + sizeof(bc_struct);
|
||||||
temp->n_ptr = (char *) safe_pemalloc(1, length, scale, persistent);
|
|
||||||
temp->n_value = temp->n_ptr;
|
temp->n_value = temp->n_ptr;
|
||||||
memset(temp->n_ptr, 0, length + scale);
|
memset(temp->n_ptr, 0, length + scale);
|
||||||
return temp;
|
return temp;
|
||||||
|
@ -61,10 +60,6 @@ void _bc_free_num_ex(bc_num *num, bool persistent)
|
||||||
}
|
}
|
||||||
(*num)->n_refs--;
|
(*num)->n_refs--;
|
||||||
if ((*num)->n_refs == 0) {
|
if ((*num)->n_refs == 0) {
|
||||||
if ((*num)->n_ptr) {
|
|
||||||
/* PHP Change: free() -> pefree(), removed free_list code */
|
|
||||||
pefree((*num)->n_ptr, persistent);
|
|
||||||
}
|
|
||||||
pefree(*num, persistent);
|
pefree(*num, persistent);
|
||||||
}
|
}
|
||||||
*num = NULL;
|
*num = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue