Skip to content

Commit 7b1ec82

Browse files
committed
FEAT: allowed to make block! using pair!
resolves: Oldes/Rebol-wishes#26
1 parent bbbdfc4 commit 7b1ec82

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/core/t-block.c

+7
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ static void No_Nones_Or_Logic(REBVAL *arg) {
353353
goto done;
354354
}
355355

356+
// use `make block! pair!` for block preallocation
357+
if (IS_PAIR(arg)) {
358+
len = (REBCNT)MAX(1, VAL_PAIR_X_INT(arg)) * (REBCNT)MAX(1, VAL_PAIR_Y_INT(arg));
359+
Set_Series(type, value, Make_Block(len));
360+
return;
361+
}
362+
356363
// else not supported make block! ...
357364
Trap_Arg(arg);
358365

src/tests/units/make-test.r3

+3-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ Rebol [
227227
--assert error? try [make block! quote 4% ] ; percent!
228228
--assert error? try [make block! quote $4 ] ; money!
229229
--assert error? try [make block! quote #"a" ] ; char!
230-
--assert error? try [make block! quote 2x2 ] ; pair!
230+
--assert [] = try [make block! quote 2x2 ] ; pair! - preallocated for at least 4 values
231+
--assert [] = try [make block! quote 0x2.2 ] ; pair! - preallocated for at least 2 values (1*2)
232+
--assert [] = try [make block! quote 2x-2 ] ; pair! - preallocated for at least 2 values (2*1)
231233
--assert error? try [make block! quote 1.1.1 ] ; tuple!
232234
--assert error? try [make block! quote 10:00 ] ; time!
233235
--assert error? try [make block! quote 2000-01-01 ] ; date!

0 commit comments

Comments
 (0)