@@ -152,7 +152,7 @@ class prevector {
152
152
struct {
153
153
char * indirect;
154
154
size_type capacity;
155
- };
155
+ } indirect_contents ;
156
156
};
157
157
#pragma pack(pop)
158
158
alignas (char *) direct_or_indirect _union = {};
@@ -163,8 +163,8 @@ class prevector {
163
163
164
164
T* direct_ptr (difference_type pos) { return reinterpret_cast <T*>(_union.direct ) + pos; }
165
165
const T* direct_ptr (difference_type pos) const { return reinterpret_cast <const T*>(_union.direct ) + pos; }
166
- T* indirect_ptr (difference_type pos) { return reinterpret_cast <T*>(_union.indirect ) + pos; }
167
- const T* indirect_ptr (difference_type pos) const { return reinterpret_cast <const T*>(_union.indirect ) + pos; }
166
+ T* indirect_ptr (difference_type pos) { return reinterpret_cast <T*>(_union.indirect_contents . indirect ) + pos; }
167
+ const T* indirect_ptr (difference_type pos) const { return reinterpret_cast <const T*>(_union.indirect_contents . indirect ) + pos; }
168
168
bool is_direct () const { return _size <= N; }
169
169
170
170
void change_capacity (size_type new_capacity) {
@@ -182,17 +182,17 @@ class prevector {
182
182
/* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert
183
183
success. These should instead use an allocator or new/delete so that handlers
184
184
are called as necessary, but performance would be slightly degraded by doing so. */
185
- _union.indirect = static_cast <char *>(realloc (_union.indirect , ((size_t )sizeof (T)) * new_capacity));
186
- assert (_union.indirect );
187
- _union.capacity = new_capacity;
185
+ _union.indirect_contents . indirect = static_cast <char *>(realloc (_union. indirect_contents .indirect , ((size_t )sizeof (T)) * new_capacity));
186
+ assert (_union.indirect_contents . indirect );
187
+ _union.indirect_contents . capacity = new_capacity;
188
188
} else {
189
189
char * new_indirect = static_cast <char *>(malloc (((size_t )sizeof (T)) * new_capacity));
190
190
assert (new_indirect);
191
191
T* src = direct_ptr (0 );
192
192
T* dst = reinterpret_cast <T*>(new_indirect);
193
193
memcpy (dst, src, size () * sizeof (T));
194
- _union.indirect = new_indirect;
195
- _union.capacity = new_capacity;
194
+ _union.indirect_contents . indirect = new_indirect;
195
+ _union.indirect_contents . capacity = new_capacity;
196
196
_size += N + 1 ;
197
197
}
198
198
}
@@ -301,7 +301,7 @@ class prevector {
301
301
if (is_direct ()) {
302
302
return N;
303
303
} else {
304
- return _union.capacity ;
304
+ return _union.indirect_contents . capacity ;
305
305
}
306
306
}
307
307
@@ -468,8 +468,8 @@ class prevector {
468
468
clear ();
469
469
}
470
470
if (!is_direct ()) {
471
- free (_union.indirect );
472
- _union.indirect = nullptr ;
471
+ free (_union.indirect_contents . indirect );
472
+ _union.indirect_contents . indirect = nullptr ;
473
473
}
474
474
}
475
475
@@ -521,7 +521,7 @@ class prevector {
521
521
if (is_direct ()) {
522
522
return 0 ;
523
523
} else {
524
- return ((size_t )(sizeof (T))) * _union.capacity ;
524
+ return ((size_t )(sizeof (T))) * _union.indirect_contents . capacity ;
525
525
}
526
526
}
527
527
0 commit comments