Skip to content

Commit 6624a7e

Browse files
committed
FEAT: added optional compilation define to turn-of mapp key normalization
Related issues: metaeducation/rebol-issues#2353 metaeducation/rebol-issues#2354
1 parent 904c078 commit 6624a7e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/core/t-map.c

+23
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@
5353

5454
#include "sys-core.h"
5555

56+
// Use following define to speed map creation a little bit as the key words
57+
// will not be normalized to set-words and or words when using words-of
58+
59+
//#define DO_NOT_NORMALIZE_MAP_KEYS
60+
61+
// with this define you would get:
62+
// [a b:] = words-of make map! [a 1 b: 2]
63+
// [a 1 b: 2] = body-of make map! [a 1 b: 2]
64+
//
65+
// else:
66+
// [a b] = words-of make map! [a 1 b: 2]
67+
// [a: 1 b: 2] = body-of make map! [a 1 b: 2]
68+
69+
70+
5671

5772
/***********************************************************************
5873
**
@@ -229,6 +244,7 @@
229244
}
230245

231246
// Create new entry:
247+
#ifndef DO_NOT_NORMALIZE_MAP_KEYS
232248
// append key
233249
if(ANY_WORD(key) && VAL_TYPE(key) != REB_SET_WORD) {
234250
// Normalize the KEY (word) to be a SET-WORD
@@ -238,6 +254,9 @@
238254
} else {
239255
Append_Val(series, key);
240256
}
257+
#else
258+
Append_Val(series, key);
259+
#endif
241260
// append value
242261
Append_Val(series, val); // no Copy_Series_Value(val) on strings
243262

@@ -369,13 +388,17 @@
369388
out = BLK_HEAD(blk);
370389
for (val = BLK_HEAD(mapser); NOT_END(val) && NOT_END(val+1); val += 2) {
371390
if (!IS_NONE(val+1)) {
391+
#ifndef DO_NOT_NORMALIZE_MAP_KEYS
372392
if (what < 0) {
373393
// words-of
374394
*out++ = val[0];
375395
if (ANY_WORD(val)) VAL_SET(out - 1, REB_WORD);
376396
}
377397
else if (what == 0)
378398
*out++ = val[0]; // body-of
399+
#else
400+
if (what <= 0) *out++ = val[0]; // words-of or body-of
401+
#endif
379402
if (what >= 0) *out++ = val[1]; // values
380403
}
381404
}

0 commit comments

Comments
 (0)