ObjFW  Check-in [7d0a27a751]

Overview
Comment:Get rid of float in OFMutableDictionary.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7d0a27a75124951d931a984c447614e3df610a1cb08a6d8382823fa28e76512b
User & Date: js on 2009-12-05 13:19:04
Other Links: manifest | tags
Context
2009-12-05
16:33
Improve OFDictionary. check-in: 725b23f325 user: js tags: trunk
13:19
Get rid of float in OFMutableDictionary. check-in: 7d0a27a751 user: js tags: trunk
11:06
Add +[isSubclassOfClass:] to OFObject. check-in: c7bfcc9e92 user: js tags: trunk
Changes

Modified src/OFMutableDictionary.m from [a2b20d13ec] to [5b1e163002].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#define BUCKET_SIZE sizeof(struct of_dictionary_bucket)

static OF_INLINE void
resize(id self, Class isa, size_t count, struct of_dictionary_bucket **data,
    size_t *size)
{
	float fill = (float)count / *size;
	size_t newsize;
	struct of_dictionary_bucket *newdata;
	uint32_t i;

	if (fill > 0.75) {
		if (*size > SIZE_MAX / 2)
			@throw [OFOutOfRangeException newWithClass: isa];

		newsize = *size * 2;
	} else if (fill < 0.25)
		newsize = *size / 2;
	else
		return;

	newdata = [self allocMemoryForNItems: newsize
				    withSize: BUCKET_SIZE];
	memset(newdata, 0, newsize * BUCKET_SIZE);








|




|
|


|
|
|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#define BUCKET_SIZE sizeof(struct of_dictionary_bucket)

static OF_INLINE void
resize(id self, Class isa, size_t count, struct of_dictionary_bucket **data,
    size_t *size)
{
	size_t fill = count * 4 / *size;
	size_t newsize;
	struct of_dictionary_bucket *newdata;
	uint32_t i;

	if (fill > 3) {
		if (*size > SIZE_MAX / 8)
			@throw [OFOutOfRangeException newWithClass: isa];

		newsize = *size << 1;
	} else if (fill < 1)
		newsize = *size >> 1;
	else
		return;

	newdata = [self allocMemoryForNItems: newsize
				    withSize: BUCKET_SIZE];
	memset(newdata, 0, newsize * BUCKET_SIZE);