ObjFW  Diff

Differences From Artifact [c7e408a064]:

To Artifact [076c9e7d74]:


54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74

75
76
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
108
109
110
111
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
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
108
109
110
111







-
+












-
+














-
+














-
+







{
	return data;
}

- (void*)item: (size_t)item
{
	if (item >= items)
		@throw [OFOutOfRangeException newWithObject: self];
		@throw [OFOutOfRangeException newWithClass: [self class]];

	return data + item * itemsize;
}

- (void*)last
{
	return data + (items - 1) * itemsize;
}

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

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

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

	return self;
}

- addNItems: (size_t)nitems
 fromCArray: (void*)carray
{
	if (nitems > SIZE_MAX - items)
		@throw [OFOutOfRangeException newWithObject: self];
		@throw [OFOutOfRangeException newWithClass: [self class]];

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

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

	return self;
}

- removeNItems: (size_t)nitems
{
	if (nitems > items)
		@throw [OFOutOfRangeException newWithObject: self];
		@throw [OFOutOfRangeException newWithClass: [self class]];

	data = [self resizeMem: data
		      toNItems: items - nitems
			ofSize: itemsize];

	items -= nitems;

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
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
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
170
171
172

173
174
175
176
177
178
179
180
181
182
183
184
185
186







-
+



















-
+



















-
+













}

- add: (void*)item
{
	size_t nsize;

	if (SIZE_MAX - items < 1 || items + 1 > SIZE_MAX / itemsize)
		@throw [OFOutOfRangeException newWithObject: self];
		@throw [OFOutOfRangeException newWithClass: [self class]];

	nsize = ((items + 1) * itemsize + lastpagebyte) & ~lastpagebyte;

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

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

	return self;
}

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

	if (nitems > SIZE_MAX - items || items + nitems > SIZE_MAX / itemsize)
		@throw [OFOutOfRangeException newWithObject: self];
		@throw [OFOutOfRangeException newWithClass: [self class]];

	nsize = ((items + nitems) * itemsize + lastpagebyte) & ~lastpagebyte;

	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)
		@throw [OFOutOfRangeException newWithObject: self];
		@throw [OFOutOfRangeException newWithClass: [self class]];

	nsize = ((items - nitems) * itemsize + lastpagebyte) & ~lastpagebyte;

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

	items -= nitems;
	size = nsize;

	return self;
}
@end