Skip to content

Commit

Permalink
primops: Err on the side of less stack usage
Browse files Browse the repository at this point in the history
Try to stay away from stack overflows.

These small vectors use stack space. Most instances will not need
to allocate because in general most things are small, and large
things are worth heap allocating.

16 * 3 * word = 384 bytes is still quite a bit, but these functions
tend not to be part of deep recursions.
  • Loading branch information
roberth committed Nov 16, 2023
1 parent cb4d082 commit 3af090d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
return result;
};

boost::container::small_vector<Value, 64> values(es->size());
boost::container::small_vector<Value, 16> values(es->size());
Value * vTmpP = values.data();

for (auto & [i_pos, i] : *es) {
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ static void prim_removeAttrs(EvalState & state, const PosIdx pos, Value * * args
/* Get the attribute names to be removed.
We keep them as Attrs instead of Symbols so std::set_difference
can be used to remove them from attrs[0]. */
boost::container::small_vector<Attr, 64> names;
boost::container::small_vector<Attr, 16> names;
names.reserve(args[1]->listSize());
for (auto elem : args[1]->listItems()) {
state.forceStringNoCtx(*elem, pos, "while evaluating the values of the second argument passed to builtins.removeAttrs");
Expand Down Expand Up @@ -3452,7 +3452,7 @@ static void prim_concatMap(EvalState & state, const PosIdx pos, Value * * args,
state.forceList(*args[1], pos, "while evaluating the second argument passed to builtins.concatMap");
auto nrLists = args[1]->listSize();

boost::container::small_vector<Value, 64> lists(nrLists);
boost::container::small_vector<Value, 16> lists(nrLists);
size_t len = 0;

for (unsigned int n = 0; n < nrLists; ++n) {
Expand Down

0 comments on commit 3af090d

Please sign in to comment.