GitHub

Original file line numberDiff line numberDiff line change

@@ -61,12 +61,12 @@ end

6161

`MRB_STACK_EXTEND_DOUBLING`

6262
6363

- If defined doubles the stack size when extending it.

64-

- Otherwise extends stack with `MRB_STACK_GROWTH`.

64+

- Otherwise extends stack with 1.5x growth (minimum `MRB_STACK_GROWTH`).

6565
6666

`MRB_STACK_GROWTH`

6767
6868

- Default value is `128`.

69-

- Used in stack extending.

69+

- Minimum stack growth size when extending.

7070

- Ignored when `MRB_STACK_EXTEND_DOUBLING` is defined.

7171
7272

`MRB_STACK_MAX`

Original file line numberDiff line numberDiff line change

@@ -169,13 +169,17 @@ stack_extend_alloc(mrb_state *mrb, mrb_int room)

169169

else

170170

size += room;

171171

#else

172-

/* Use linear stack growth.

172+

/* Use 1.5x stack growth.

173173

It is slightly slower than doubling the stack space,

174174

but it saves memory on small devices. */

175-

if (room <= MRB_STACK_GROWTH)

176-

size += MRB_STACK_GROWTH;

177-

else

178-

size += room;

175+

{

176+

size_t newsize = size + (size >> 1); /* 1.5x growth */

177+

if (newsize < size + MRB_STACK_GROWTH)

178+

newsize = size + MRB_STACK_GROWTH;

179+

if (newsize < size + (size_t)room)

180+

newsize = size + room;

181+

size = newsize;

182+

}

179183

#endif

180184
181185

mrb_value *newstack = (mrb_value*)mrb_realloc(mrb, mrb->c->stbase, sizeof(mrb_value) * size);

Read the original on github.com ↗