Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2020-12-01 07:41:41 +0300
committerDaniel Bevenius <daniel.bevenius@gmail.com>2020-12-04 10:45:13 +0300
commitff28ab77a97f4edd6a48b6939be41e2ab5cef8a9 (patch)
tree99ebde4fa33d523a0f1d3a39b1d20548201e109f /src/env.cc
parente4614e87b59a89e55aad5453b496d4d8d78cb568 (diff)
src: remove some duplication in DeserializeProps
This commit introduces a new macro to reduce som code duplication in Environment::DeserializeProperties. PR-URL: https://github.com/nodejs/node/pull/36336 Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/env.cc b/src/env.cc
index eef0e9dc300..3e03ba9121f 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -1346,17 +1346,17 @@ void Environment::DeserializeProperties(const EnvSerializeInfo* info) {
const std::vector<PropInfo>& templates = info->persistent_templates;
size_t i = 0; // index to the array
size_t id = 0;
-#define V(PropertyName, TypeName) \
+#define SetProperty(PropertyName, TypeName, vector, type, from) \
do { \
- if (templates.size() > i && id == templates[i].id) { \
- const PropInfo& d = templates[i]; \
+ if (vector.size() > i && id == vector[i].id) { \
+ const PropInfo& d = vector[i]; \
DCHECK_EQ(d.name, #PropertyName); \
MaybeLocal<TypeName> maybe_field = \
- isolate_->GetDataFromSnapshotOnce<TypeName>(d.index); \
+ from->GetDataFromSnapshotOnce<TypeName>(d.index); \
Local<TypeName> field; \
if (!maybe_field.ToLocal(&field)) { \
fprintf(stderr, \
- "Failed to deserialize environment template " #PropertyName \
+ "Failed to deserialize environment " #type " " #PropertyName \
"\n"); \
} \
set_##PropertyName(field); \
@@ -1364,32 +1364,19 @@ void Environment::DeserializeProperties(const EnvSerializeInfo* info) {
} \
} while (0); \
id++;
+#define V(PropertyName, TypeName) SetProperty(PropertyName, TypeName, \
+ templates, template, isolate_)
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V);
#undef V
i = 0; // index to the array
id = 0;
const std::vector<PropInfo>& values = info->persistent_values;
-#define V(PropertyName, TypeName) \
- do { \
- if (values.size() > i && id == values[i].id) { \
- const PropInfo& d = values[i]; \
- DCHECK_EQ(d.name, #PropertyName); \
- MaybeLocal<TypeName> maybe_field = \
- ctx->GetDataFromSnapshotOnce<TypeName>(d.index); \
- Local<TypeName> field; \
- if (!maybe_field.ToLocal(&field)) { \
- fprintf(stderr, \
- "Failed to deserialize environment value " #PropertyName \
- "\n"); \
- } \
- set_##PropertyName(field); \
- i++; \
- } \
- } while (0); \
- id++;
+#define V(PropertyName, TypeName) SetProperty(PropertyName, TypeName, \
+ values, value, ctx)
ENVIRONMENT_STRONG_PERSISTENT_VALUES(V);
#undef V
+#undef SetProperty
MaybeLocal<Context> maybe_ctx_from_snapshot =
ctx->GetDataFromSnapshotOnce<Context>(info->context);