ObjFW  Diff

Differences From Artifact [490fab954b]:

To Artifact [1c8a76eb56]:


253
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268

- (void)addItem: (const void*)item
{
	if (SIZE_MAX - count < 1)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	data = [self resizeMemory: data
			 toNItems: count + 1
			   ofSize: itemSize];


	memcpy(data + count * itemSize, item, itemSize);

	count++;
}

- (void)insertItem: (const void*)item







<
|
>







253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268

- (void)addItem: (const void*)item
{
	if (SIZE_MAX - count < 1)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	data = [self resizeMemory: data

			 itemSize: itemSize
			    count: count + 1];

	memcpy(data + count * itemSize, item, itemSize);

	count++;
}

- (void)insertItem: (const void*)item
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
- (void)addItemsFromCArray: (const void*)cArray
		     count: (size_t)nItems
{
	if (nItems > SIZE_MAX - count)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	data = [self resizeMemory: data
			 toNItems: count + nItems
			   ofSize: itemSize];


	memcpy(data + count * itemSize, cArray, nItems * itemSize);
	count += nItems;
}

- (void)insertItemsFromCArray: (const void*)cArray
		      atIndex: (size_t)index
			count: (size_t)nItems
{
	if (nItems > SIZE_MAX - count || index > count)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	data = [self resizeMemory: data
			 toNItems: count + nItems
			   ofSize: itemSize];


	memmove(data + (index + nItems) * itemSize, data + index * itemSize,
	    (count - index) * itemSize);
	memcpy(data + index * itemSize, cArray, nItems * itemSize);

	count += nItems;
}







<
|
>













<
|
>







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
- (void)addItemsFromCArray: (const void*)cArray
		     count: (size_t)nItems
{
	if (nItems > SIZE_MAX - count)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	data = [self resizeMemory: data

			 itemSize: itemSize
			    count: count + nItems];

	memcpy(data + count * itemSize, cArray, nItems * itemSize);
	count += nItems;
}

- (void)insertItemsFromCArray: (const void*)cArray
		      atIndex: (size_t)index
			count: (size_t)nItems
{
	if (nItems > SIZE_MAX - count || index > count)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	data = [self resizeMemory: data

			 itemSize: itemSize
			    count: count + nItems];

	memmove(data + (index + nItems) * itemSize, data + index * itemSize,
	    (count - index) * itemSize);
	memcpy(data + index * itemSize, cArray, nItems * itemSize);

	count += nItems;
}
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
	memmove(data + range.start * itemSize,
	    data + (range.start + range.length) * itemSize,
	    (count - range.start - range.length) * itemSize);

	count -= range.length;
	@try {
		data = [self resizeMemory: data
				 toNItems: count
				   ofSize: itemSize];

	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
	}
}

- (void)removeLastItem
{
	if (count < 1)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	count--;
	@try {
		data = [self resizeMemory: data
				 toNItems: count
				   ofSize: itemSize];

	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only made it smaller */
	}
}

- (void)removeAllItems
{







<
|
>













<
|
>







318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
348
	memmove(data + range.start * itemSize,
	    data + (range.start + range.length) * itemSize,
	    (count - range.start - range.length) * itemSize);

	count -= range.length;
	@try {
		data = [self resizeMemory: data

				 itemSize: itemSize
				    count: count];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
	}
}

- (void)removeLastItem
{
	if (count < 1)
		@throw [OFOutOfRangeException exceptionWithClass: isa];

	count--;
	@try {
		data = [self resizeMemory: data

				 itemSize: itemSize
				    count: count];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only made it smaller */
	}
}

- (void)removeAllItems
{
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
	count--;
	lastPageByte = of_pagesize - 1;
	newSize = (count * itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize) {
		@try {
			data = [self resizeMemory: data
					 toNItems: count
					   ofSize: newSize];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't care, as we only made it smaller */
		}

		size = newSize;
	}
}







<
|







565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
	count--;
	lastPageByte = of_pagesize - 1;
	newSize = (count * itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize) {
		@try {
			data = [self resizeMemory: data

					   toSize: newSize];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't care, as we only made it smaller */
		}

		size = newSize;
	}
}