ObjFW  Check-in [3b59111e0a]

Overview
Comment:Create a copy of the key in OFDictionary.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3b59111e0a692c0af902dddf28930b781320c0d31195b0557b324376dce5a966
User & Date: js on 2009-05-18 18:57:08
Other Links: manifest | tags
Context
2009-05-18
19:08
Add - isEqual: for OFArray. check-in: 66293c1fe8 user: js tags: trunk
18:57
Create a copy of the key in OFDictionary. check-in: 3b59111e0a user: js tags: trunk
18:52
- copy and - mutableCopy should never autorelease. check-in: 7fa61023b9 user: js tags: trunk
Changes

Modified src/OFDictionary.h from [03b66f6ea0] to [aa683549c8].

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

/**
 * Sets a key to an object. A key can be any object.
 *
 * \param key The key to set
 * \param obj The object to set the key to
 */
- set: (OFObject*)key
   to: (OFObject*)obj;

/**
 * \param key The key whose object should be returned
 * \return The object for the given key or nil if the key was not found
 */
- (id)get: (OFObject*)key;







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

/**
 * Sets a key to an object. A key can be any object.
 *
 * \param key The key to set
 * \param obj The object to set the key to
 */
- set: (OFObject <OFCopying>*)key
   to: (OFObject*)obj;

/**
 * \param key The key whose object should be returned
 * \return The object for the given key or nil if the key was not found
 */
- (id)get: (OFObject*)key;

Modified src/OFDictionary.m from [9d6c8f24dc] to [22afc84d9d].

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126


127





128




129
130
131
132
133
134
135
	for (i = 0; i < size; i++)
		if (data[i] != nil)
			[data[i] release];

	[super dealloc];
}

- set: (OFObject*)key
   to: (OFObject*)obj
{
	uint32_t hash;
	of_list_object_t *iter;

	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						    andSelector: _cmd];

	hash = [key hash] & (size - 1);

	if (data[hash] == nil)
		data[hash] = [[OFList alloc] init];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) {
		if ([iter->object isEqual: key]) {
			[iter->next->object release];
			[obj retain];
			iter->next->object = obj;

			return self;
		}
	}



	[data[hash] append: key];





	[data[hash] append: obj];





	return self;
}

- (id)get: (OFObject*)key
{
	uint32_t hash;







|



|




















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







95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
	for (i = 0; i < size; i++)
		if (data[i] != nil)
			[data[i] release];

	[super dealloc];
}

- set: (OFObject <OFCopying>*)key
   to: (OFObject*)obj
{
	uint32_t hash;
	of_list_object_t *iter, *key_obj;

	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						    andSelector: _cmd];

	hash = [key hash] & (size - 1);

	if (data[hash] == nil)
		data[hash] = [[OFList alloc] init];

	for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) {
		if ([iter->object isEqual: key]) {
			[iter->next->object release];
			[obj retain];
			iter->next->object = obj;

			return self;
		}
	}

	key = [key copy];
	@try {
		key_obj = [data[hash] append: key];
	} @finally {
		[key release];
	}

	@try {
		[data[hash] append: obj];
	} @catch (OFException *e) {
		[data[hash] remove: key_obj];
		@throw e;
	}

	return self;
}

- (id)get: (OFObject*)key
{
	uint32_t hash;