Project

General

Profile

Feature #13725 ยป 0001-Hash-deduplicates-string-keys-if-and-only-if-fstring.patch

normalperson (Eric Wong), 07/07/2017 12:08 AM

View differences:

hash.c
18 18
#include "probes.h"
19 19
#include "id.h"
20 20
#include "symbol.h"
21
#include "gc.h"
21 22

  
22 23
#ifdef __APPLE__
23 24
# ifdef HAVE_CRT_EXTERNS_H
......
1518 1519
static int
1519 1520
hash_aset_str(st_data_t *key, st_data_t *val, struct update_arg *arg, int existing)
1520 1521
{
1521
    if (!existing) {
1522
	*key = rb_str_new_frozen(*key);
1522
    if (!existing && !RB_OBJ_FROZEN(*key)) {
1523
	VALUE fstr;
1524
	st_table *tbl = rb_vm_fstring_table();
1525

  
1526
	if (st_lookup(tbl, *key, (st_data_t *)&fstr)) {
1527
	    if (rb_objspace_garbage_object_p(fstr)) {
1528
		*key = rb_fstring(*key);
1529
	    }
1530
	    else {
1531
		*key = fstr;
1532
	    }
1533
	}
1534
	else {
1535
	    *key = rb_str_new_frozen(*key);
1536
	}
1523 1537
    }
1524 1538
    return hash_aset(key, val, arg, existing);
1525 1539
}
1526
-