Skip to content

Commit 344888d

Browse files
committed
implement review feedback and fix comment
1 parent dc8f650 commit 344888d

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Include/internal/pycore_c_array.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef Py_INTERNAL_C_ARRAY_H
22
#define Py_INTERNAL_C_ARRAY_H
3+
34
#ifdef __cplusplus
45
extern "C" {
56
#endif
@@ -18,19 +19,20 @@ extern "C" {
1819
* item_size: size of each array entry
1920
*
2021
* If *array is NULL, allocate default_alloc entries.
21-
* Otherwise, grow the array by default_alloc entries.
22+
* Otherwise, double the array size if idx is out of range.
2223
*
23-
* return 0 if successful and -1 (with exception set) otherwise.
24+
* Return 0 if successful and -1 (with exception set) otherwise.
2425
*/
2526
int _Py_EnsureArrayLargeEnough(
26-
int idx,
27-
void **array,
28-
int *alloc,
29-
int delta,
30-
size_t item_size);
27+
int idx,
28+
void **array,
29+
int *alloc,
30+
int initial_size,
31+
size_t item_size);
3132

3233

3334
#ifdef __cplusplus
3435
}
3536
#endif
37+
3638
#endif /* !Py_INTERNAL_C_ARRAY_H */

Include/internal/pycore_compile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ extern "C" {
1111
#include <stdbool.h>
1212

1313
#include "pycore_ast.h" // mod_ty
14-
#include "pycore_c_array.h" // _Py_EnsureArrayLargeEnough()
1514
#include "pycore_symtable.h" // _Py_SourceLocation
1615
#include "pycore_instruction_sequence.h"
1716

Python/codegen.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ static const int compare_masks[] = {
115115
* idx: the index we want to access
116116
* arr: pointer to the array
117117
* alloc: pointer to the capacity of the array
118-
* default_alloc: initial number of items
118+
* initial_size: initial number of items
119119
* item_size: size of each item
120120
*
121121
*/
122122
int
123123
_Py_EnsureArrayLargeEnough(int idx, void **array, int *alloc,
124-
int default_alloc, size_t item_size)
124+
int initial_size, size_t item_size)
125125
{
126126
void *arr = *array;
127127
if (arr == NULL) {
128-
int new_alloc = default_alloc;
128+
int new_alloc = initial_size;
129129
if (idx >= new_alloc) {
130-
new_alloc = idx + default_alloc;
130+
new_alloc = idx + initial_size;
131131
}
132132
arr = PyMem_Calloc(new_alloc, item_size);
133133
if (arr == NULL) {
@@ -140,7 +140,7 @@ _Py_EnsureArrayLargeEnough(int idx, void **array, int *alloc,
140140
size_t oldsize = *alloc * item_size;
141141
int new_alloc = *alloc << 1;
142142
if (idx >= new_alloc) {
143-
new_alloc = idx + default_alloc;
143+
new_alloc = idx + initial_size;
144144
}
145145
size_t newsize = new_alloc * item_size;
146146

0 commit comments

Comments
 (0)