Skip to content

Commit 5d49999

Browse files
DesWurstesfanquake
authored andcommitted
prevector: Avoid unnamed struct, which is a GNU extension
1 parent afed2e9 commit 5d49999

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/prevector.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class prevector {
152152
struct {
153153
char* indirect;
154154
size_type capacity;
155-
};
155+
} indirect_contents;
156156
};
157157
#pragma pack(pop)
158158
alignas(char*) direct_or_indirect _union = {};
@@ -163,8 +163,8 @@ class prevector {
163163

164164
T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
165165
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; }
168168
bool is_direct() const { return _size <= N; }
169169

170170
void change_capacity(size_type new_capacity) {
@@ -182,17 +182,17 @@ class prevector {
182182
/* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert
183183
success. These should instead use an allocator or new/delete so that handlers
184184
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;
188188
} else {
189189
char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
190190
assert(new_indirect);
191191
T* src = direct_ptr(0);
192192
T* dst = reinterpret_cast<T*>(new_indirect);
193193
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;
196196
_size += N + 1;
197197
}
198198
}
@@ -301,7 +301,7 @@ class prevector {
301301
if (is_direct()) {
302302
return N;
303303
} else {
304-
return _union.capacity;
304+
return _union.indirect_contents.capacity;
305305
}
306306
}
307307

@@ -468,8 +468,8 @@ class prevector {
468468
clear();
469469
}
470470
if (!is_direct()) {
471-
free(_union.indirect);
472-
_union.indirect = nullptr;
471+
free(_union.indirect_contents.indirect);
472+
_union.indirect_contents.indirect = nullptr;
473473
}
474474
}
475475

@@ -521,7 +521,7 @@ class prevector {
521521
if (is_direct()) {
522522
return 0;
523523
} else {
524-
return ((size_t)(sizeof(T))) * _union.capacity;
524+
return ((size_t)(sizeof(T))) * _union.indirect_contents.capacity;
525525
}
526526
}
527527

0 commit comments

Comments
 (0)