ObjFW  Check-in [f447af977a]

Overview
Comment:runtime/hashtable.m: Move some code around
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f447af977aa766e57fe3fea5dff696fbb1c5e5c3d7126a37bb1d037c6c9c48ca
User & Date: js on 2014-04-08 16:38:15
Other Links: manifest | tags
Context
2014-04-08
17:01
OFArray_adjacent: Optimize fast enumeration check-in: 4dbca9fc06 user: js tags: trunk
16:38
runtime/hashtable.m: Move some code around check-in: f447af977a user: js tags: trunk
2014-04-06
14:40
runtime/hashtable.m: Add support for deletion check-in: c2d9134d88 user: js tags: trunk
Changes

Modified src/OFStdIOStream.m from [5073a1b1d8] to [8d9bbeeba6].

150
151
152
153
154
155
156
157
158
159
160
	return OF_RETAIN_COUNT_MAX;
}

- (void)dealloc
{
	OF_UNRECOGNIZED_SELECTOR

	/* Get rid of stupid warning */
	[super dealloc];
}
@end







|



150
151
152
153
154
155
156
157
158
159
160
	return OF_RETAIN_COUNT_MAX;
}

- (void)dealloc
{
	OF_UNRECOGNIZED_SELECTOR

	/* Get rid of a stupid warning */
	[super dealloc];
}
@end

Modified src/runtime/class.m from [0fb0e5fd5b] to [fb4bbc3736].

901
902
903
904
905
906
907

908


909
910
911
912
913
914
915
			void *cls = (Class)classes->data[i]->obj;

			if (cls == Nil || (uintptr_t)cls & 1)
				continue;

			objc_unregister_class(cls);


			/* The table might have been resized, so start again */


			i = 0;
		}
	}

	assert(classes_cnt == 0);

	if (empty_dtable != NULL) {







>
|
>
>







901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
			void *cls = (Class)classes->data[i]->obj;

			if (cls == Nil || (uintptr_t)cls & 1)
				continue;

			objc_unregister_class(cls);

			/*
			 * The table might have been resized, so go back to the
			 * start again.
			 */
			i = 0;
		}
	}

	assert(classes_cnt == 0);

	if (empty_dtable != NULL) {

Modified src/runtime/hashtable.m from [4dfb42e01c] to [f9c1f2768d].

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
	}

	free(table->data);
	table->data = ndata;
	table->size = nsize;
}

static void
insert(struct objc_hashtable *table, const void *key, const void *obj)
{
	uint32_t i, hash, last;
	struct objc_hashtable_bucket *bucket;

	resize(table, table->count + 1);

	hash = table->hash(key);
	last = table->size;

	for (i = hash & (table->size - 1); i < last && table->data[i] != NULL &&
	    table->data[i] != &objc_deleted_bucket; i++);

	if (i >= last) {
		last = hash & (table->size - 1);

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

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

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

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

	table->data[i] = bucket;
	table->count++;
}

static inline bool
index_for_key(struct objc_hashtable *table, const void *key, uint32_t *index)
{
	uint32_t i, hash;

	hash = table->hash(key) & (table->size - 1);








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







123
124
125
126
127
128
129



































130
131
132
133
134
135
136
	}

	free(table->data);
	table->data = ndata;
	table->size = nsize;
}




































static inline bool
index_for_key(struct objc_hashtable *table, const void *key, uint32_t *index)
{
	uint32_t i, hash;

	hash = table->hash(key) & (table->size - 1);

195
196
197
198
199
200
201
202

203
204
205
206
207
208

























209

210
211
212
213
214
215
216
	return false;
}

void
objc_hashtable_set(struct objc_hashtable *table, const void *key,
    const void *obj)
{
	uint32_t idx;


	if (!index_for_key(table, key, &idx)) {
		insert(table, key, obj);
		return;
	}


























	table->data[idx]->obj = obj;

}

void*
objc_hashtable_get(struct objc_hashtable *table, const void *key)
{
	uint32_t idx;








|
>

|
|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>







160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
	return false;
}

void
objc_hashtable_set(struct objc_hashtable *table, const void *key,
    const void *obj)
{
	uint32_t i, hash, last;
	struct objc_hashtable_bucket *bucket;

	if (index_for_key(table, key, &i)) {
		table->data[i]->obj = obj;
		return;
	}

	resize(table, table->count + 1);

	hash = table->hash(key);
	last = table->size;

	for (i = hash & (table->size - 1); i < last && table->data[i] != NULL &&
	    table->data[i] != &objc_deleted_bucket; i++);

	if (i >= last) {
		last = hash & (table->size - 1);

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

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

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

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

	table->data[i] = bucket;
	table->count++;
}

void*
objc_hashtable_get(struct objc_hashtable *table, const void *key)
{
	uint32_t idx;