ObjFW  Check-in [db15314420]

Overview
Comment:OFList: Avoid -[allocMemoryWithSize:]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: db15314420b27a3666c87d73bb96f16009d5dabaec2f77a2f464f54f25c0a5b0
User & Date: js on 2020-11-06 00:58:06
Other Links: manifest | tags
Context
2020-11-06
01:11
OF*Data: Avoid -[allocMemoryWithSize:] check-in: 1a70abc65d user: js tags: trunk
00:58
OFList: Avoid -[allocMemoryWithSize:] check-in: db15314420 user: js tags: trunk
2020-11-05
02:35
Remove -[allocZeroedMemoryWithSize:] check-in: 2bb3136a7f user: js tags: trunk
Changes

Modified src/OFList.m from [2cea85f754] to [17f16f253f].

77
78
79
80
81
82
83


84
85
86



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	}

	return self;
}

- (void)dealloc
{


	for (of_list_object_t *iter = _firstListObject;
	    iter != NULL; iter = iter->next)
		[iter->object release];




	[super dealloc];
}

- (of_list_object_t *)appendObject: (id)object
{
	of_list_object_t *listObject;

	listObject = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	listObject->object = [object retain];
	listObject->next = NULL;
	listObject->previous = _lastListObject;

	if (_lastListObject != NULL)
		_lastListObject->next = listObject;








>
>

|

>
>
>








|







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
	}

	return self;
}

- (void)dealloc
{
	of_list_object_t *next;

	for (of_list_object_t *iter = _firstListObject;
	    iter != NULL; iter = next) {
		[iter->object release];
		next = iter->next;
		free(iter);
	}

	[super dealloc];
}

- (of_list_object_t *)appendObject: (id)object
{
	of_list_object_t *listObject;

	listObject = of_malloc(1, sizeof(of_list_object_t));
	listObject->object = [object retain];
	listObject->next = NULL;
	listObject->previous = _lastListObject;

	if (_lastListObject != NULL)
		_lastListObject->next = listObject;

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
	return listObject;
}

- (of_list_object_t *)prependObject: (id)object
{
	of_list_object_t *listObject;

	listObject = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	listObject->object = [object retain];
	listObject->next = _firstListObject;
	listObject->previous = NULL;

	if (_firstListObject != NULL)
		_firstListObject->previous = listObject;








|







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	return listObject;
}

- (of_list_object_t *)prependObject: (id)object
{
	of_list_object_t *listObject;

	listObject = of_malloc(1, sizeof(of_list_object_t));
	listObject->object = [object retain];
	listObject->next = _firstListObject;
	listObject->previous = NULL;

	if (_firstListObject != NULL)
		_firstListObject->previous = listObject;

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
}

- (of_list_object_t *)insertObject: (id)object
		  beforeListObject: (of_list_object_t *)listObject
{
	of_list_object_t *newListObject;

	newListObject = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	newListObject->object = [object retain];
	newListObject->next = listObject;
	newListObject->previous = listObject->previous;

	if (listObject->previous != NULL)
		listObject->previous->next = newListObject;








|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
}

- (of_list_object_t *)insertObject: (id)object
		  beforeListObject: (of_list_object_t *)listObject
{
	of_list_object_t *newListObject;

	newListObject = of_malloc(1, sizeof(of_list_object_t));
	newListObject->object = [object retain];
	newListObject->next = listObject;
	newListObject->previous = listObject->previous;

	if (listObject->previous != NULL)
		listObject->previous->next = newListObject;

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
}

- (of_list_object_t *)insertObject: (id)object
		   afterListObject: (of_list_object_t *)listObject
{
	of_list_object_t *newListObject;

	newListObject = [self allocMemoryWithSize: sizeof(of_list_object_t)];
	newListObject->object = [object retain];
	newListObject->next = listObject->next;
	newListObject->previous = listObject;

	if (listObject->next != NULL)
		listObject->next->previous = newListObject;








|







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
}

- (of_list_object_t *)insertObject: (id)object
		   afterListObject: (of_list_object_t *)listObject
{
	of_list_object_t *newListObject;

	newListObject = of_malloc(1, sizeof(of_list_object_t));
	newListObject->object = [object retain];
	newListObject->next = listObject->next;
	newListObject->previous = listObject;

	if (listObject->next != NULL)
		listObject->next->previous = newListObject;

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
	if (_lastListObject == listObject)
		_lastListObject = listObject->previous;

	_count--;
	_mutations++;

	[listObject->object release];

	[self freeMemory: listObject];
}

- (id)firstObject
{
	return (_firstListObject != NULL ? _firstListObject->object : nil);
}








<
|







198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
	if (_lastListObject == listObject)
		_lastListObject = listObject->previous;

	_count--;
	_mutations++;

	[listObject->object release];

	free(listObject);
}

- (id)firstObject
{
	return (_firstListObject != NULL ? _firstListObject->object : nil);
}

268
269
270
271
272
273
274
275
276
277
278

279

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
			return true;

	return false;
}

- (void)removeAllObjects
{
	of_list_object_t *iter, *next;

	_mutations++;


	for (iter = _firstListObject; iter != NULL; iter = next) {

		next = iter->next;

		[iter->object release];
		[self freeMemory: iter];
	}

	_firstListObject = _lastListObject = NULL;
}

- (id)copy
{
	OFList *copy = [[[self class] alloc] init];
	of_list_object_t *listObject, *previous;

	listObject = NULL;
	previous = NULL;

	@try {
		for (of_list_object_t *iter = _firstListObject;
		    iter != NULL; iter = iter->next) {
			listObject = [copy allocMemoryWithSize:
			    sizeof(of_list_object_t)];
			listObject->object = [iter->object retain];
			listObject->next = NULL;
			listObject->previous = previous;

			if (copy->_firstListObject == NULL)
				copy->_firstListObject = listObject;
			if (previous != NULL)







|



>
|
>

|
<
<
















<
|







272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311
			return true;

	return false;
}

- (void)removeAllObjects
{
	of_list_object_t *next;

	_mutations++;

	for (of_list_object_t *iter = _firstListObject;
	    iter != NULL; iter = next) {
		[iter->object release];
		next = iter->next;
		free(iter);


	}

	_firstListObject = _lastListObject = NULL;
}

- (id)copy
{
	OFList *copy = [[[self class] alloc] init];
	of_list_object_t *listObject, *previous;

	listObject = NULL;
	previous = NULL;

	@try {
		for (of_list_object_t *iter = _firstListObject;
		    iter != NULL; iter = iter->next) {

			listObject = of_malloc(1, sizeof(of_list_object_t));
			listObject->object = [iter->object retain];
			listObject->next = NULL;
			listObject->previous = previous;

			if (copy->_firstListObject == NULL)
				copy->_firstListObject = listObject;
			if (previous != NULL)