From 0c2265da85bd094376279aea5e282974784218b3 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 12 May 2021 09:43:58 -0600 Subject: [PATCH] unique_ptr for valmap --- src/libexpr/eval.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index f8391cd77..531e3f752 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -616,17 +616,21 @@ std::optional EvalState::getDoc(Value & v) return {}; } -static std::optional> map1(const char *name, Value *v) __attribute__((noinline)); -std::optional> map1(const char *name, Value *v) +// typedef std::optional> valmap; +typedef const std::map valmap; + +static std::unique_ptr map1(const char *name, Value *v) __attribute__((noinline)); +std::unique_ptr map1(const char *name, Value *v) { - return std::optional>({{name, v}}); + // return new valmap({{name, v}}); + return std::unique_ptr(new valmap({{name, v}})); } -static std::optional> map2(const char *name1, Value *v1, const char *name2, Value *v2) __attribute__((noinline)); -std::optional> map2(const char *name1, Value *v1, const char *name2, Value *v2) +static std::unique_ptr map2(const char *name1, Value *v1, const char *name2, Value *v2) __attribute__((noinline)); +std::unique_ptr map2(const char *name1, Value *v1, const char *name2, Value *v2) { - return std::optional>({{name1, v1},{name2, v2}}); + return std::unique_ptr(new valmap({{name1, v1}, {name2, v2}})); } /* Every "format" object (even temporary) takes up a few hundred bytes @@ -669,7 +673,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & p1, const char * s, const }); } -LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const std::optional> & env)) +LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, std::unique_ptr env)) { auto error = TypeError({ .msg = hintfmt(s), @@ -681,7 +685,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const throw error; } -LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v, const std::optional> & env)) +LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v, std::unique_ptr env)) { auto error = TypeError({ .msg = hintfmt(s, v), @@ -693,7 +697,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const throw error; } -LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2, const std::optional> & env)) +LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2, std::unique_ptr env)) { auto error = TypeError({ .msg = hintfmt(s, fun.showNamePos(), s2), @@ -723,7 +727,7 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char * }); } -LocalNoInlineNoReturn(void throwMissingArgumentError(const Pos & pos, const char * s, const string & s1, const std::optional> & env)) +LocalNoInlineNoReturn(void throwMissingArgumentError(const Pos & pos, const char * s, const string & s1, std::unique_ptr env)) { auto error = MissingArgumentError({ .msg = hintfmt(s, s1),