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
112
113
114
115
116
|
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
112
113
114
115
116
|
-
+
-
+
-
+
-
+
|
{
return data;
}
- (void*)item: (size_t)item
{
if (item >= items)
@throw [OFOutOfRangeException newWithClass: [self class]];
@throw [OFOutOfRangeException newWithClass: isa];
return data + item * itemsize;
}
- (void*)last
{
return data + (items - 1) * itemsize;
}
- add: (void*)item
{
if (SIZE_MAX - items < 1 || items + 1 > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: [self class]];
@throw [OFOutOfRangeException newWithClass: isa];
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 || items + nitems > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: [self class]];
@throw [OFOutOfRangeException newWithClass: isa];
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 newWithClass: [self class]];
@throw [OFOutOfRangeException newWithClass: isa];
data = [self resizeMem: data
toNItems: items - nitems
ofSize: itemsize];
items -= nitems;
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
-
+
-
+
|
}
- (int)compare: (id)obj
{
int ret;
if (![obj isKindOf: [OFArray class]])
@throw [OFInvalidArgumentException newWithClass: [self class]
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
if ([obj itemsize] != itemsize)
@throw [OFInvalidArgumentException newWithClass: [self class]
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
if ([obj items] == items)
return memcmp(data, [obj data], items * itemsize);
if (items > [obj items]) {
if ((ret = memcmp(data, [obj data], [obj items] * itemsize)))
|
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
-
+
-
+
-
+
|
}
- add: (void*)item
{
size_t nsize;
if (SIZE_MAX - items < 1 || items + 1 > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: [self class]];
@throw [OFOutOfRangeException newWithClass: isa];
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 newWithClass: [self class]];
@throw [OFOutOfRangeException newWithClass: isa];
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 newWithClass: [self class]];
@throw [OFOutOfRangeException newWithClass: isa];
nsize = ((items - nitems) * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMem: data
toSize: nsize];
|