Skip to content

Commit 5728820

Browse files
committed
src: remove some duplication in DeserializeProps
This commit introduces a new macro to reduce som code duplication in Environment::DeserializeProperties.
1 parent cb023a3 commit 5728820

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

src/env.cc

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,50 +1344,37 @@ void Environment::DeserializeProperties(const EnvSerializeInfo* info) {
13441344
const std::vector<PropInfo>& templates = info->persistent_templates;
13451345
size_t i = 0; // index to the array
13461346
size_t id = 0;
1347-
#define V(PropertyName, TypeName) \
1347+
#define SetProperty(PropertyName, TypeName, vector, type, from) \
13481348
do { \
1349-
if (templates.size() > i && id == templates[i].id) { \
1350-
const PropInfo& d = templates[i]; \
1349+
if (vector.size() > i && id == vector[i].id) { \
1350+
const PropInfo& d = vector[i]; \
13511351
DCHECK_EQ(d.name, #PropertyName); \
13521352
MaybeLocal<TypeName> maybe_field = \
1353-
isolate_->GetDataFromSnapshotOnce<TypeName>(d.index); \
1353+
from->GetDataFromSnapshotOnce<TypeName>(d.index); \
13541354
Local<TypeName> field; \
13551355
if (!maybe_field.ToLocal(&field)) { \
13561356
fprintf(stderr, \
1357-
"Failed to deserialize environment template " #PropertyName \
1357+
"Failed to deserialize environment " #type " " #PropertyName \
13581358
"\n"); \
13591359
} \
13601360
set_##PropertyName(field); \
13611361
i++; \
13621362
} \
13631363
} while (0); \
13641364
id++;
1365+
#define V(PropertyName, TypeName) SetProperty(PropertyName, TypeName, \
1366+
templates, template, isolate_)
13651367
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V);
13661368
#undef V
13671369

13681370
i = 0; // index to the array
13691371
id = 0;
13701372
const std::vector<PropInfo>& values = info->persistent_values;
1371-
#define V(PropertyName, TypeName) \
1372-
do { \
1373-
if (values.size() > i && id == values[i].id) { \
1374-
const PropInfo& d = values[i]; \
1375-
DCHECK_EQ(d.name, #PropertyName); \
1376-
MaybeLocal<TypeName> maybe_field = \
1377-
ctx->GetDataFromSnapshotOnce<TypeName>(d.index); \
1378-
Local<TypeName> field; \
1379-
if (!maybe_field.ToLocal(&field)) { \
1380-
fprintf(stderr, \
1381-
"Failed to deserialize environment value " #PropertyName \
1382-
"\n"); \
1383-
} \
1384-
set_##PropertyName(field); \
1385-
i++; \
1386-
} \
1387-
} while (0); \
1388-
id++;
1373+
#define V(PropertyName, TypeName) SetProperty(PropertyName, TypeName, \
1374+
values, value, ctx)
13891375
ENVIRONMENT_STRONG_PERSISTENT_VALUES(V);
13901376
#undef V
1377+
#undef SetProperty
13911378

13921379
MaybeLocal<Context> maybe_ctx_from_snapshot =
13931380
ctx->GetDataFromSnapshotOnce<Context>(info->context);

0 commit comments

Comments
 (0)