ObjFW  Diff

Differences From Artifact [18ec5ebfcc]:

  • File src/OFList.m — part of check-in [bbf1f79b8f] at 2009-09-08 16:06:10 on branch trunk — New OFDictionary implementation and removal of a hack in OFList.

    The new implementation is easier to use as it does automatic resizing,
    but therefore it's not realtime-capable anymore. The new implementation
    should also be a little bit faster.

    I decided to change the implementation as only very few need a
    realtime-capable dictionary and those few will most likely write their
    own implementation for their specific case anyway.

    As the new implementation no longer uses OFList, this also made it
    possible to remove a hack from OFList. (user: js, size: 3923) [annotate] [blame] [check-ins using]

To Artifact [b22035331b]:


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	first = NULL;
	last = NULL;
	retain_and_release = YES;

	return self;
}

- initWithoutRetainAndRelease
{
	self = [super init];

	first = NULL;
	last = NULL;

	return self;
}

- (void)dealloc







<
<
<
<
<
<
<
<
<
<
<







22
23
24
25
26
27
28











29
30
31
32
33
34
35
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];












	first = NULL;
	last = NULL;

	return self;
}

- (void)dealloc
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

	last = o;
	if (first == NULL)
		first = o;

	count++;

	if (retain_and_release)
		[obj retain];

	return o;
}

- (of_list_object_t*)prepend: (id)obj
{
	of_list_object_t *o;







<
|







66
67
68
69
70
71
72

73
74
75
76
77
78
79
80

	last = o;
	if (first == NULL)
		first = o;

	count++;


	[obj retain];

	return o;
}

- (of_list_object_t*)prepend: (id)obj
{
	of_list_object_t *o;
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

	first = o;
	if (last == NULL)
		last = o;

	count++;

	if (retain_and_release)
		[obj retain];

	return o;
}

- (of_list_object_t*)insert: (id)obj
		     before: (of_list_object_t*)listobj
{







<
|







89
90
91
92
93
94
95

96
97
98
99
100
101
102
103

	first = o;
	if (last == NULL)
		last = o;

	count++;


	[obj retain];

	return o;
}

- (of_list_object_t*)insert: (id)obj
		     before: (of_list_object_t*)listobj
{
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
	listobj->prev = o;

	if (listobj == first)
		first = o;

	count++;

	if (retain_and_release)
		[obj retain];

	return o;
}

- (of_list_object_t*)insert: (id)obj
		      after: (of_list_object_t*)listobj
{







<
|







114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
	listobj->prev = o;

	if (listobj == first)
		first = o;

	count++;


	[obj retain];

	return o;
}

- (of_list_object_t*)insert: (id)obj
		      after: (of_list_object_t*)listobj
{
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
	listobj->next = o;

	if (listobj == last)
		last = o;

	count++;

	if (retain_and_release)
		[obj retain];

	return o;
}

- remove: (of_list_object_t*)listobj
{
	if (listobj->prev != NULL)
		listobj->prev->next = listobj->next;
	if (listobj->next != NULL)
		listobj->next->prev = listobj->prev;

	if (first == listobj)
		first = listobj->next;
	if (last == listobj)
		last = listobj->prev;

	count--;

	if (retain_and_release)
		[listobj->object release];

	[self freeMemory: listobj];

	return self;
}

- (size_t)count







<
|


















<
|







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
172
	listobj->next = o;

	if (listobj == last)
		last = o;

	count++;


	[obj retain];

	return o;
}

- remove: (of_list_object_t*)listobj
{
	if (listobj->prev != NULL)
		listobj->prev->next = listobj->next;
	if (listobj->next != NULL)
		listobj->next->prev = listobj->prev;

	if (first == listobj)
		first = listobj->next;
	if (last == listobj)
		last = listobj->prev;

	count--;


	[listobj->object release];

	[self freeMemory: listobj];

	return self;
}

- (size_t)count
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
	assert(iter == NULL && iter2 == NULL);

	return YES;
}

- (id)copy
{
	OFList *new;
	of_list_object_t *iter, *o, *prev;

	if (retain_and_release)
		new = [[OFList alloc] init];
	else
		new = [[OFList alloc] initWithoutRetainAndRelease];

	o = NULL;
	prev = NULL;

	@try {
		for (iter = first; iter != NULL; iter = iter->next) {
			o = [new allocMemoryWithSize: sizeof(of_list_object_t)];
			o->object = iter->object;
			o->next = NULL;
			o->prev = prev;

			if (new->first == NULL)
				new->first = o;
			if (prev != NULL)
				prev->next = o;

			new->count++;

			if (retain_and_release)
				[o->object retain];

			prev = o;
		}
	} @catch (OFException *e) {
		[new release];
		@throw e;
	}

	new->last = o;

	return new;
}
@end







|


<
<
<
<
<

















<
|













193
194
195
196
197
198
199
200
201
202





203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
	assert(iter == NULL && iter2 == NULL);

	return YES;
}

- (id)copy
{
	OFList *new = [[OFList alloc] init];
	of_list_object_t *iter, *o, *prev;






	o = NULL;
	prev = NULL;

	@try {
		for (iter = first; iter != NULL; iter = iter->next) {
			o = [new allocMemoryWithSize: sizeof(of_list_object_t)];
			o->object = iter->object;
			o->next = NULL;
			o->prev = prev;

			if (new->first == NULL)
				new->first = o;
			if (prev != NULL)
				prev->next = o;

			new->count++;


			[o->object retain];

			prev = o;
		}
	} @catch (OFException *e) {
		[new release];
		@throw e;
	}

	new->last = o;

	return new;
}
@end