ObjFW  Check-in [6cef79231a]

Overview
Comment:Fix a minor bug in OFDictionary's -[initWithObject:forKey:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6cef79231a22aef8d4dedec8cf7ec8b50e1a9515112a754ec7bfc30415f98978
User & Date: js on 2010-03-18 14:23:13
Other Links: manifest | tags
Context
2010-03-18
15:25
Mach-O needs this initialized, even though we never access it. check-in: cd2b957955 user: js tags: trunk
14:23
Fix a minor bug in OFDictionary's -[initWithObject:forKey:]. check-in: 6cef79231a user: js tags: trunk
13:49
Fix a bug with deleted buckets in OFDictionary + a few optimizations. check-in: e3f22b34ea user: js tags: trunk
Changes

Modified src/OFDictionary.m from [33cef06086] to [ff5369c591].

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

172
173
174
175
176
177
178

	return self;
}

- initWithObject: (OFObject*)obj
	  forKey: (OFObject <OFCopying>*)key
{


	self = [self init];


















	@try {
		key = [key copy];
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	@try {
		[obj retain];
	} @catch (OFException *e) {
		[key release];
		[self dealloc];
		@throw e;
	}

	data[0].key = key;
	data[0].object = obj;
	data[0].hash = [key hash];


	return self;
}

- initWithObjects: (OFArray*)objs
	  forKeys: (OFArray*)keys
{







>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>















|
|
|
>







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
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

	return self;
}

- initWithObject: (OFObject*)obj
	  forKey: (OFObject <OFCopying>*)key
{
	uint32_t i;

	self = [self init];

	@try {
		data = [self allocMemoryForNItems: 2
					 withSize: BUCKET_SIZE];
	} @catch (OFException *e) {
		/*
		 * We can't use [super dealloc] on OS X here. Compiler bug?
		 * Anyway, we didn't do anything yet anyway, so [self dealloc]
		 * works.
		 */
		[self dealloc];
		@throw e;
	}
	memset(data, 0, 2 * BUCKET_SIZE);
	size = 2;

	i = [key hash] & 1;

	@try {
		key = [key copy];
	} @catch (OFException *e) {
		[self dealloc];
		@throw e;
	}

	@try {
		[obj retain];
	} @catch (OFException *e) {
		[key release];
		[self dealloc];
		@throw e;
	}

	data[i].key = key;
	data[i].object = obj;
	data[i].hash = [key hash];
	count = 1;

	return self;
}

- initWithObjects: (OFArray*)objs
	  forKeys: (OFArray*)keys
{