ObjFW  Diff

Differences From Artifact [97782e7ade]:

To Artifact [c474c9a944]:


1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18


19
20
21
22
23
24
25
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdio.h>
#import <string.h>


#import "OFArray.h"

#import "OFExceptions.h"
#import "OFMacros.h"



@implementation OFArray
+ newWithItemSize: (size_t)is
{
	return [[OFArray alloc] initWithItemSize: is];
}














>





>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdio.h>
#import <string.h>
#import <unistd.h>

#import "OFArray.h"

#import "OFExceptions.h"
#import "OFMacros.h"

static size_t pagesize = 0;

@implementation OFArray
+ newWithItemSize: (size_t)is
{
	return [[OFArray alloc] initWithItemSize: is];
}

60
61
62
63
64
65
66



67
68
69
70
71
72
73
- (void*)last
{
	return data + (items - 1) * itemsize;
}

- add: (void*)item
{



	data = [self resizeMem: data
		      toNItems: items + 1
			ofSize: itemsize];

	memcpy(data + items++ * itemsize, item, itemsize);

	return self;







>
>
>







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
- (void*)last
{
	return data + (items - 1) * itemsize;
}

- add: (void*)item
{
	if (SIZE_MAX - items < 1)
		[[OFOutOfRangeException newWithObject: self] raise];

	data = [self resizeMem: data
		      toNItems: items + 1
			ofSize: itemsize];

	memcpy(data + items++ * itemsize, item, itemsize);

	return self;
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
+ newWithItemSize: (size_t)is
{
	return [[OFBigArray alloc] initWithItemSize: is];
}

- initWithItemSize: (size_t)is
{



	if ((self = [super init]))
		size = 0;

	return self;
}

- addNItems: (size_t)nitems
 fromCArray: (void*)carray
{

	/* FIXME */


	OF_NOT_IMPLEMENTED(self)

}











- removeNItems: (size_t)nitems
{

	/* FIXME */


	OF_NOT_IMPLEMENTED(self)

}









@end







>
>
>
|








>
|
>
>
|
>
|
>
>
>

>
>
>
>
>
>
>


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

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
+ newWithItemSize: (size_t)is
{
	return [[OFBigArray alloc] initWithItemSize: is];
}

- initWithItemSize: (size_t)is
{
	if (pagesize == 0)
		pagesize = getpagesize();

	if ((self = [super initWithItemSize: is]))
		size = 0;

	return self;
}

- addNItems: (size_t)nitems
 fromCArray: (void*)carray
{
	size_t nsize;

	if (nitems > SIZE_MAX - items || items + nitems > SIZE_MAX / itemsize)
		[[OFOutOfRangeException newWithObject: self] raise];

	nsize = (((items + nitems) * itemsize) / pagesize) + 1;

	if (size != nsize)
		data = [self resizeMem: data
				toSize: nsize];

	memcpy(data + items * itemsize, carray, nitems * itemsize);
	items += nitems;
	size = nsize;

	return self;
}

- removeNItems: (size_t)nitems
{
	size_t nsize;

	if (nitems > items)
		[[OFOutOfRangeException newWithObject: self] raise];

	nsize = (((items - nitems) * itemsize) / pagesize) + 1;

	if (size != nsize)
		data = [self resizeMem: data
				toSize: nsize];

	items -= nitems;
	size = nsize;

	return self;
}
@end