File tree 1 file changed +15
-2
lines changed
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 3
3
** REBOL [R3] Language Interpreter and Run-time Environment
4
4
**
5
5
** Copyright 2012 REBOL Technologies
6
- ** Copyright 2012-2021 Rebol Open Source Contributors
6
+ ** Copyright 2012-2022 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");
@@ -242,7 +242,20 @@ static REBCNT *CRC32_Table = 0;
242
242
break ;
243
243
244
244
case REB_TUPLE :
245
- ret = Hash_String (VAL_TUPLE (val ), VAL_TUPLE_LEN (val ));
245
+ if (VAL_TUPLE_LEN (val ) <= 4 ) {
246
+ // For colors (tuple of size 4) there may be used Knuth's multiplicative hash.
247
+ // Knuth's multiplication constant is 2654435761L, but it may be different as long
248
+ // as it is:
249
+ // 1. Odd number (Otherwise we may lose the highest bit.)
250
+ // 2. Has no long streaks of ones or zeros.
251
+ ret = ((REBCNT )VAL_INT32 (val ) * 2654435761L ) >> 26 ;
252
+ // The higher bits contain more mixture from the multiplication,
253
+ // so the shift is not 32, but just 26.
254
+
255
+ // In Brotli compressor the constant is 506832829L and the shift is 18.
256
+ } else {
257
+ ret = Hash_String (VAL_TUPLE (val ), VAL_TUPLE_LEN (val ));
258
+ }
246
259
break ;
247
260
248
261
case REB_PAIR :
You can’t perform that action at this time.
0 commit comments