|
3 | 3 | ** REBOL [R3] Language Interpreter and Run-time Environment |
4 | 4 | ** |
5 | 5 | ** Copyright 2012 REBOL Technologies |
6 | | -** Copyright 2012-2025 Rebol Open Source Contributors |
| 6 | +** Copyright 2012-2026 Rebol Open Source Contributors |
7 | 7 | ** REBOL is a trademark of REBOL Technologies |
8 | 8 | ** |
9 | 9 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
|
137 | 137 | /* |
138 | 138 | ** Makes a MAP block (that holds both keys and values). |
139 | 139 | ** Size is the number of key-value pairs. |
140 | | -** Hash series is also created. |
| 140 | +** Hash series is not created yet. |
141 | 141 | ** |
142 | 142 | ***********************************************************************/ |
143 | 143 | { |
|
147 | 147 | CLEAR_SERIES(blk); |
148 | 148 |
|
149 | 149 | // Use hashing only when there is more then MIN_DICT keys. |
150 | | - if (size > MIN_DICT) ser = Make_Hash_Array(size); |
| 150 | + //if (size > MIN_DICT) ser = Make_Hash_Array(size); |
151 | 151 |
|
152 | 152 | blk->series = ser; |
153 | 153 |
|
|
450 | 450 | ** |
451 | 451 | */ REBSER *Copy_Map(REBVAL *val, REBU64 types) |
452 | 452 | /* |
453 | | -** Copy given map. |
| 453 | +** Copy the given map's key/value pairs. Don't hash until necessary. |
454 | 454 | ** |
455 | 455 | ***********************************************************************/ |
456 | 456 | { |
457 | 457 | REBSER *series; |
| 458 | + ASSERT1(IS_MAP(val) || IS_BLOCK(val) || IS_PAREN(val), RP_INTERNAL); |
458 | 459 | series = Make_Map(VAL_BLK_LEN(val) / 2); |
459 | | - //COPY_BLK_PART(series, VAL_BLK_DATA(data), n); |
460 | | - Append_Map(series, val, UNKNOWN); |
| 460 | + if (IS_MAP(val)) { |
| 461 | + // There should be valid key/value pairs, so just copying is sufficient. |
| 462 | + COPY_BLK_PART(series, VAL_BLK(val), VAL_TAIL(val)); |
| 463 | + // If existing series has a hashtable, reuse it. |
| 464 | + if (VAL_SERIES(val)->series) |
| 465 | + series->series = Copy_Series(VAL_SERIES(val)->series); |
| 466 | + } |
| 467 | + else { |
| 468 | + // There may be duplicates, so we must append each key/value pair. |
| 469 | + Append_Map(series, val, UNKNOWN); |
| 470 | + } |
461 | 471 | if (types != 0) Copy_Deep_Values(series, 0, SERIES_TAIL(series), types); |
462 | | - Rehash_Hash(series); |
| 472 | + //Rehash_Hash(series); // It will be rehashed only when needed. |
463 | 473 | return series; |
464 | 474 | } |
465 | 475 |
|
|
471 | 481 | { |
472 | 482 | REBCNT n; |
473 | 483 | // REBSER *series; |
474 | | - |
475 | | - if (!IS_BLOCK(data) && !IS_MAP(data)) return FALSE; |
| 484 | + if (!(IS_BLOCK(data) || IS_MAP(data) || IS_PAREN(data))) |
| 485 | + return FALSE; |
476 | 486 |
|
477 | 487 | n = VAL_BLK_LEN(data); |
478 | 488 | if (n & 1) return FALSE; |
|
0 commit comments