ObjFW  Diff

Differences From Artifact [f9877d131a]:

To Artifact [3bc4ddb944]:


48
49
50
51
52
53
54
55

56
57
58
59
60
61
62

63
64
65
66
67
68
69
48
49
50
51
52
53
54

55
56
57
58
59
60
61

62
63
64
65
66
67
68
69







-
+






-
+







struct objc_hashtable*
objc_hashtable_new(uint32_t size)
{
	struct objc_hashtable *h;
	uint32_t i;

	if ((h = malloc(sizeof(struct objc_hashtable))) == NULL)
		ERROR("Not enough memory to allocate hash table!");
		OBJC_ERROR("Not enough memory to allocate hash table!");

	h->count = 0;
	h->last_idx = size - 1;
	h->data = malloc(size * sizeof(struct objc_hashtable_bucket*));

	if (h->data == NULL)
		ERROR("Not enough memory to allocate hash table!");
		OBJC_ERROR("Not enough memory to allocate hash table!");

	for (i = 0; i < size; i++)
		h->data[i] = NULL;

	return h;
}

80
81
82
83
84
85
86
87


88
89
90
91
92
93
94
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95







-
+
+







		struct objc_hashtable_bucket **ndata;
		uint32_t nsize = (h->last_idx + 1) << 1;

		assert(nsize > 0);

		ndata = malloc(nsize * sizeof(struct objc_hashtable_bucket*));
		if (ndata == NULL)
			ERROR("Not enough memory to insert into hash table!");
			OBJC_ERROR("Not enough memory to insert into hash "
			    "table!");

		for (i = 0; i < nsize; i++)
			ndata[i] = NULL;

		for (i = 0; i <= h->last_idx; i++) {
			if (h->data[i] != NULL) {
				uint32_t j;
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117







-
+







					last = h->data[i]->hash & (nsize - 1);

					for (j = 0; j < last &&
					    ndata[j] != NULL; j++);
				}

				if (j >= last)
					ERROR("No free bucket!");
					OBJC_ERROR("No free bucket!");

				ndata[j] = h->data[i];
			}
		}

		free(h->data);
		h->data = ndata;
124
125
126
127
128
129
130
131

132
133
134

135
136
137
138
139
140
141
125
126
127
128
129
130
131

132
133
134

135
136
137
138
139
140
141
142







-
+


-
+







	if (i >= last) {
		last = hash & h->last_idx;

		for (i = 0; i < last && h->data[i] != NULL; i++);
	}

	if (i >= last)
		ERROR("No free bucket!");
		OBJC_ERROR("No free bucket!");

	if ((bucket = malloc(sizeof(struct objc_hashtable_bucket))) == NULL)
		ERROR("Not enough memory to allocate hash table bucket!");
		OBJC_ERROR("Not enough memory to allocate hash table bucket!");

	bucket->key = key;
	bucket->hash = hash;
	bucket->obj = obj;

	h->data[i] = bucket;
	h->count++;