Combine VECTOR_RESIZE and VECTOR_RESERVE
This commit is contained in:
parent
d2eb866abe
commit
5e11a738c6
@ -242,7 +242,7 @@ static void clear_devlist(vector_DevMap *devlist)
|
|||||||
AL_STRING_DEINIT((i)->device_name); \
|
AL_STRING_DEINIT((i)->device_name); \
|
||||||
} while(0)
|
} while(0)
|
||||||
VECTOR_FOR_EACH(DevMap, *devlist, FREE_DEV);
|
VECTOR_FOR_EACH(DevMap, *devlist, FREE_DEV);
|
||||||
VECTOR_RESIZE(*devlist, 0);
|
VECTOR_RESIZE(*devlist, 0, 0);
|
||||||
#undef FREE_DEV
|
#undef FREE_DEV
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ static void clear_devlist(vector_DevMap *list)
|
|||||||
{
|
{
|
||||||
#define DEINIT_STR(i) AL_STRING_DEINIT((i)->name)
|
#define DEINIT_STR(i) AL_STRING_DEINIT((i)->name)
|
||||||
VECTOR_FOR_EACH(DevMap, *list, DEINIT_STR);
|
VECTOR_FOR_EACH(DevMap, *list, DEINIT_STR);
|
||||||
VECTOR_RESIZE(*list, 0);
|
VECTOR_RESIZE(*list, 0, 0);
|
||||||
#undef DEINIT_STR
|
#undef DEINIT_STR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ static void clear_devlist(vector_DevMap *list)
|
|||||||
(i)->devid = NULL; \
|
(i)->devid = NULL; \
|
||||||
} while(0)
|
} while(0)
|
||||||
VECTOR_FOR_EACH(DevMap, *list, CLEAR_DEVMAP);
|
VECTOR_FOR_EACH(DevMap, *list, CLEAR_DEVMAP);
|
||||||
VECTOR_RESIZE(*list, 0);
|
VECTOR_RESIZE(*list, 0, 0);
|
||||||
#undef CLEAR_DEVMAP
|
#undef CLEAR_DEVMAP
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,11 +258,7 @@ static HRESULT probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, ve
|
|||||||
if(SUCCEEDED(hr) && count > 0)
|
if(SUCCEEDED(hr) && count > 0)
|
||||||
{
|
{
|
||||||
clear_devlist(list);
|
clear_devlist(list);
|
||||||
if(!VECTOR_RESERVE(*list, count))
|
VECTOR_RESIZE(*list, 0, count);
|
||||||
{
|
|
||||||
IMMDeviceCollection_Release(coll);
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flowdir,
|
hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flowdir,
|
||||||
eMultimedia, &defdev);
|
eMultimedia, &defdev);
|
||||||
|
@ -443,7 +443,7 @@ static void clear_devlist(vector_DevMap *list)
|
|||||||
#define DEINIT_STRS(i) (AL_STRING_DEINIT((i)->name),AL_STRING_DEINIT((i)->device_name))
|
#define DEINIT_STRS(i) (AL_STRING_DEINIT((i)->name),AL_STRING_DEINIT((i)->device_name))
|
||||||
VECTOR_FOR_EACH(DevMap, *list, DEINIT_STRS);
|
VECTOR_FOR_EACH(DevMap, *list, DEINIT_STRS);
|
||||||
#undef DEINIT_STRS
|
#undef DEINIT_STRS
|
||||||
VECTOR_RESIZE(*list, 0);
|
VECTOR_RESIZE(*list, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,8 +117,7 @@ static void deviceList(int type, vector_DevMap *devmap)
|
|||||||
if(max_cards < 0)
|
if(max_cards < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
VECTOR_RESERVE(*devmap, max_cards+1);
|
VECTOR_RESIZE(*devmap, 0, max_cards+1);
|
||||||
VECTOR_RESIZE(*devmap, 0);
|
|
||||||
|
|
||||||
entry.name = strdup(qsaDevice);
|
entry.name = strdup(qsaDevice);
|
||||||
entry.card = 0;
|
entry.card = 0;
|
||||||
@ -893,8 +892,8 @@ void alc_qsa_probe(enum DevProbe type)
|
|||||||
case ALL_DEVICE_PROBE:
|
case ALL_DEVICE_PROBE:
|
||||||
#define FREE_NAME(iter) free((iter)->name)
|
#define FREE_NAME(iter) free((iter)->name)
|
||||||
VECTOR_FOR_EACH(DevMap, DeviceNameMap, FREE_NAME);
|
VECTOR_FOR_EACH(DevMap, DeviceNameMap, FREE_NAME);
|
||||||
|
VECTOR_RESIZE(DeviceNameMap, 0, 0);
|
||||||
#undef FREE_NAME
|
#undef FREE_NAME
|
||||||
VECTOR_RESIZE(DeviceNameMap, 0);
|
|
||||||
|
|
||||||
deviceList(SND_PCM_CHANNEL_PLAYBACK, &DeviceNameMap);
|
deviceList(SND_PCM_CHANNEL_PLAYBACK, &DeviceNameMap);
|
||||||
#define APPEND_DEVICE(iter) AppendAllDevicesList((iter)->name)
|
#define APPEND_DEVICE(iter) AppendAllDevicesList((iter)->name)
|
||||||
@ -905,8 +904,8 @@ void alc_qsa_probe(enum DevProbe type)
|
|||||||
case CAPTURE_DEVICE_PROBE:
|
case CAPTURE_DEVICE_PROBE:
|
||||||
#define FREE_NAME(iter) free((iter)->name)
|
#define FREE_NAME(iter) free((iter)->name)
|
||||||
VECTOR_FOR_EACH(DevMap, CaptureNameMap, FREE_NAME);
|
VECTOR_FOR_EACH(DevMap, CaptureNameMap, FREE_NAME);
|
||||||
|
VECTOR_RESIZE(CaptureNameMap, 0, 0);
|
||||||
#undef FREE_NAME
|
#undef FREE_NAME
|
||||||
VECTOR_RESIZE(CaptureNameMap, 0);
|
|
||||||
|
|
||||||
deviceList(SND_PCM_CHANNEL_CAPTURE, &CaptureNameMap);
|
deviceList(SND_PCM_CHANNEL_CAPTURE, &CaptureNameMap);
|
||||||
#define APPEND_DEVICE(iter) AppendCaptureDeviceList((iter)->name)
|
#define APPEND_DEVICE(iter) AppendCaptureDeviceList((iter)->name)
|
||||||
|
@ -46,7 +46,7 @@ static vector_al_string CaptureDevices;
|
|||||||
static void clear_devlist(vector_al_string *list)
|
static void clear_devlist(vector_al_string *list)
|
||||||
{
|
{
|
||||||
VECTOR_FOR_EACH(al_string, *list, al_string_deinit);
|
VECTOR_FOR_EACH(al_string, *list, al_string_deinit);
|
||||||
VECTOR_RESIZE(*list, 0);
|
VECTOR_RESIZE(*list, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ static void ProbePlaybackDevices(void)
|
|||||||
clear_devlist(&PlaybackDevices);
|
clear_devlist(&PlaybackDevices);
|
||||||
|
|
||||||
numdevs = waveOutGetNumDevs();
|
numdevs = waveOutGetNumDevs();
|
||||||
VECTOR_RESERVE(PlaybackDevices, numdevs);
|
VECTOR_RESIZE(PlaybackDevices, 0, numdevs);
|
||||||
for(i = 0;i < numdevs;i++)
|
for(i = 0;i < numdevs;i++)
|
||||||
{
|
{
|
||||||
WAVEOUTCAPSW WaveCaps;
|
WAVEOUTCAPSW WaveCaps;
|
||||||
@ -101,7 +101,7 @@ static void ProbeCaptureDevices(void)
|
|||||||
clear_devlist(&CaptureDevices);
|
clear_devlist(&CaptureDevices);
|
||||||
|
|
||||||
numdevs = waveInGetNumDevs();
|
numdevs = waveInGetNumDevs();
|
||||||
VECTOR_RESERVE(CaptureDevices, numdevs);
|
VECTOR_RESIZE(CaptureDevices, 0, numdevs);
|
||||||
for(i = 0;i < numdevs;i++)
|
for(i = 0;i < numdevs;i++)
|
||||||
{
|
{
|
||||||
WAVEINCAPSW WaveCaps;
|
WAVEINCAPSW WaveCaps;
|
||||||
|
107
Alc/helpers.c
107
Alc/helpers.c
@ -838,51 +838,6 @@ void SetRTPriority(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_size, size_t obj_count, ALboolean exact)
|
|
||||||
{
|
|
||||||
vector_ *vecptr = (vector_*)ptr;
|
|
||||||
if((*vecptr ? (*vecptr)->Capacity : 0) < obj_count)
|
|
||||||
{
|
|
||||||
size_t old_size = (*vecptr ? (*vecptr)->Size : 0);
|
|
||||||
void *temp;
|
|
||||||
|
|
||||||
/* Use the next power-of-2 size if we don't need to allocate the exact
|
|
||||||
* amount. This is preferred when regularly increasing the vector since
|
|
||||||
* it means fewer reallocations. Though it means it also wastes some
|
|
||||||
* memory. */
|
|
||||||
if(exact == AL_FALSE && obj_count < INT_MAX)
|
|
||||||
obj_count = NextPowerOf2((ALuint)obj_count);
|
|
||||||
|
|
||||||
/* Need to be explicit with the caller type's base size, because it
|
|
||||||
* could have extra padding before the start of the array (that is,
|
|
||||||
* sizeof(*vector_) may not equal base_size). */
|
|
||||||
temp = al_calloc(16, base_size + obj_size*obj_count);
|
|
||||||
if(temp == NULL) return AL_FALSE;
|
|
||||||
if(*vecptr)
|
|
||||||
memcpy(((ALubyte*)temp)+base_size, ((ALubyte*)*vecptr)+base_size,
|
|
||||||
obj_size*old_size);
|
|
||||||
|
|
||||||
al_free(*vecptr);
|
|
||||||
*vecptr = temp;
|
|
||||||
(*vecptr)->Capacity = obj_count;
|
|
||||||
(*vecptr)->Size = old_size;
|
|
||||||
}
|
|
||||||
return AL_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALboolean vector_resize(char *ptr, size_t base_size, size_t obj_size, size_t obj_count)
|
|
||||||
{
|
|
||||||
vector_ *vecptr = (vector_*)ptr;
|
|
||||||
if(*vecptr || obj_count > 0)
|
|
||||||
{
|
|
||||||
if(!vector_reserve((char*)vecptr, base_size, obj_size, obj_count, AL_TRUE))
|
|
||||||
return AL_FALSE;
|
|
||||||
(*vecptr)->Size = obj_count;
|
|
||||||
}
|
|
||||||
return AL_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern inline void al_string_deinit(al_string *str);
|
extern inline void al_string_deinit(al_string *str);
|
||||||
extern inline size_t al_string_length(const_al_string str);
|
extern inline size_t al_string_length(const_al_string str);
|
||||||
extern inline ALboolean al_string_empty(const_al_string str);
|
extern inline ALboolean al_string_empty(const_al_string str);
|
||||||
@ -896,9 +851,8 @@ void al_string_clear(al_string *str)
|
|||||||
* is to ensure we have space to add a null terminator in the string
|
* is to ensure we have space to add a null terminator in the string
|
||||||
* data so it can be used as a C-style string.
|
* data so it can be used as a C-style string.
|
||||||
*/
|
*/
|
||||||
VECTOR_RESERVE(*str, 1);
|
VECTOR_RESIZE(*str, 0, 1);
|
||||||
VECTOR_RESIZE(*str, 0);
|
VECTOR_ELEM(*str, 0) = 0;
|
||||||
*VECTOR_END(*str) = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,11 +884,10 @@ void al_string_copy(al_string *str, const_al_string from)
|
|||||||
size_t len = al_string_length(from);
|
size_t len = al_string_length(from);
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
VECTOR_RESERVE(*str, len+1);
|
VECTOR_RESIZE(*str, len, len+1);
|
||||||
VECTOR_RESIZE(*str, len);
|
|
||||||
for(i = 0;i < len;i++)
|
for(i = 0;i < len;i++)
|
||||||
VECTOR_ELEM(*str, i) = VECTOR_ELEM(from, i);
|
VECTOR_ELEM(*str, i) = VECTOR_ELEM(from, i);
|
||||||
*VECTOR_END(*str) = 0;
|
VECTOR_ELEM(*str, i) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void al_string_copy_cstr(al_string *str, const al_string_char_type *from)
|
void al_string_copy_cstr(al_string *str, const al_string_char_type *from)
|
||||||
@ -942,11 +895,10 @@ void al_string_copy_cstr(al_string *str, const al_string_char_type *from)
|
|||||||
size_t len = strlen(from);
|
size_t len = strlen(from);
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
VECTOR_RESERVE(*str, len+1);
|
VECTOR_RESIZE(*str, len, len+1);
|
||||||
VECTOR_RESIZE(*str, len);
|
|
||||||
for(i = 0;i < len;i++)
|
for(i = 0;i < len;i++)
|
||||||
VECTOR_ELEM(*str, i) = from[i];
|
VECTOR_ELEM(*str, i) = from[i];
|
||||||
*VECTOR_END(*str) = 0;
|
VECTOR_ELEM(*str, i) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void al_string_copy_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
|
void al_string_copy_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
|
||||||
@ -954,18 +906,18 @@ void al_string_copy_range(al_string *str, const al_string_char_type *from, const
|
|||||||
size_t len = to - from;
|
size_t len = to - from;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
VECTOR_RESERVE(*str, len+1);
|
VECTOR_RESIZE(*str, len, len+1);
|
||||||
VECTOR_RESIZE(*str, len);
|
|
||||||
for(i = 0;i < len;i++)
|
for(i = 0;i < len;i++)
|
||||||
VECTOR_ELEM(*str, i) = from[i];
|
VECTOR_ELEM(*str, i) = from[i];
|
||||||
*VECTOR_END(*str) = 0;
|
VECTOR_ELEM(*str, i) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void al_string_append_char(al_string *str, const al_string_char_type c)
|
void al_string_append_char(al_string *str, const al_string_char_type c)
|
||||||
{
|
{
|
||||||
VECTOR_RESERVE(*str, al_string_length(*str)+2);
|
size_t len = al_string_length(*str);
|
||||||
|
VECTOR_RESIZE(*str, len, len+2);
|
||||||
VECTOR_PUSH_BACK(*str, c);
|
VECTOR_PUSH_BACK(*str, c);
|
||||||
*VECTOR_END(*str) = 0;
|
VECTOR_ELEM(*str, len+1) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void al_string_append_cstr(al_string *str, const al_string_char_type *from)
|
void al_string_append_cstr(al_string *str, const al_string_char_type *from)
|
||||||
@ -976,27 +928,25 @@ void al_string_append_cstr(al_string *str, const al_string_char_type *from)
|
|||||||
size_t base = al_string_length(*str);
|
size_t base = al_string_length(*str);
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
VECTOR_RESERVE(*str, base+len+1);
|
VECTOR_RESIZE(*str, base+len, base+len+1);
|
||||||
VECTOR_RESIZE(*str, base+len);
|
|
||||||
for(i = 0;i < len;i++)
|
for(i = 0;i < len;i++)
|
||||||
VECTOR_ELEM(*str, base+i) = from[i];
|
VECTOR_ELEM(*str, base+i) = from[i];
|
||||||
*VECTOR_END(*str) = 0;
|
VECTOR_ELEM(*str, base+i) = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void al_string_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
|
void al_string_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
|
||||||
{
|
{
|
||||||
if(to != from)
|
size_t len = to - from;
|
||||||
|
if(len != 0)
|
||||||
{
|
{
|
||||||
size_t base = al_string_length(*str);
|
size_t base = al_string_length(*str);
|
||||||
size_t len = to - from;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
VECTOR_RESERVE(*str, base+len+1);
|
VECTOR_RESIZE(*str, base+len, base+len+1);
|
||||||
VECTOR_RESIZE(*str, base+len);
|
|
||||||
for(i = 0;i < len;i++)
|
for(i = 0;i < len;i++)
|
||||||
VECTOR_ELEM(*str, base+i) = from[i];
|
VECTOR_ELEM(*str, base+i) = from[i];
|
||||||
*VECTOR_END(*str) = 0;
|
VECTOR_ELEM(*str, base+i) = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1006,10 +956,9 @@ void al_string_copy_wcstr(al_string *str, const wchar_t *from)
|
|||||||
int len;
|
int len;
|
||||||
if((len=WideCharToMultiByte(CP_UTF8, 0, from, -1, NULL, 0, NULL, NULL)) > 0)
|
if((len=WideCharToMultiByte(CP_UTF8, 0, from, -1, NULL, 0, NULL, NULL)) > 0)
|
||||||
{
|
{
|
||||||
VECTOR_RESERVE(*str, len);
|
VECTOR_RESIZE(*str, len-1, len);
|
||||||
VECTOR_RESIZE(*str, len-1);
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, from, -1, &VECTOR_FRONT(*str), len, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, from, -1, &VECTOR_FRONT(*str), len, NULL, NULL);
|
||||||
*VECTOR_END(*str) = 0;
|
VECTOR_ELEM(*str, len-1) = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1018,11 +967,10 @@ void al_string_append_wcstr(al_string *str, const wchar_t *from)
|
|||||||
int len;
|
int len;
|
||||||
if((len=WideCharToMultiByte(CP_UTF8, 0, from, -1, NULL, 0, NULL, NULL)) > 0)
|
if((len=WideCharToMultiByte(CP_UTF8, 0, from, -1, NULL, 0, NULL, NULL)) > 0)
|
||||||
{
|
{
|
||||||
size_t strlen = al_string_length(*str);
|
size_t base = al_string_length(*str);
|
||||||
VECTOR_RESERVE(*str, strlen+len);
|
VECTOR_RESIZE(*str, base+len-1, base+len);
|
||||||
VECTOR_RESIZE(*str, strlen+len-1);
|
WideCharToMultiByte(CP_UTF8, 0, from, -1, &VECTOR_ELEM(*str, base), len, NULL, NULL);
|
||||||
WideCharToMultiByte(CP_UTF8, 0, from, -1, &VECTOR_FRONT(*str) + strlen, len, NULL, NULL);
|
VECTOR_ELEM(*str, base+len-1) = 0;
|
||||||
*VECTOR_END(*str) = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1031,11 +979,10 @@ void al_string_append_wrange(al_string *str, const wchar_t *from, const wchar_t
|
|||||||
int len;
|
int len;
|
||||||
if((len=WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), NULL, 0, NULL, NULL)) > 0)
|
if((len=WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), NULL, 0, NULL, NULL)) > 0)
|
||||||
{
|
{
|
||||||
size_t strlen = al_string_length(*str);
|
size_t base = al_string_length(*str);
|
||||||
VECTOR_RESERVE(*str, strlen+len+1);
|
VECTOR_RESIZE(*str, base+len, base+len+1);
|
||||||
VECTOR_RESIZE(*str, strlen+len);
|
WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), &VECTOR_ELEM(*str, base), len+1, NULL, NULL);
|
||||||
WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), &VECTOR_FRONT(*str) + strlen, len+1, NULL, NULL);
|
VECTOR_ELEM(*str, base+len) = 0;
|
||||||
*VECTOR_END(*str) = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
39
Alc/vector.h
39
Alc/vector.h
@ -31,12 +31,32 @@ typedef const _##N* const_##N;
|
|||||||
#define VECTOR_INIT_STATIC() NULL
|
#define VECTOR_INIT_STATIC() NULL
|
||||||
#define VECTOR_DEINIT(_x) do { al_free((_x)); (_x) = NULL; } while(0)
|
#define VECTOR_DEINIT(_x) do { al_free((_x)); (_x) = NULL; } while(0)
|
||||||
|
|
||||||
/* Helper to increase a vector's reserve. Do not call directly. */
|
#define VECTOR_RESIZE(_x, _s, _c) do { \
|
||||||
ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_size, size_t obj_count, ALboolean exact);
|
size_t _size = (_s); \
|
||||||
#define VECTOR_RESERVE(_x, _c) (vector_reserve((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_c), AL_TRUE))
|
size_t _cap = (_c); \
|
||||||
|
if(_size > _cap) \
|
||||||
ALboolean vector_resize(char *ptr, size_t base_size, size_t obj_size, size_t obj_count);
|
_cap = _size; \
|
||||||
#define VECTOR_RESIZE(_x, _c) (vector_resize((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_c)))
|
\
|
||||||
|
if(!(_x) && _cap == 0) \
|
||||||
|
break; \
|
||||||
|
\
|
||||||
|
if(((_x) ? (_x)->Capacity : 0) < _cap) \
|
||||||
|
{ \
|
||||||
|
size_t old_size = ((_x) ? (_x)->Size : 0); \
|
||||||
|
void *temp; \
|
||||||
|
\
|
||||||
|
temp = al_calloc(16, sizeof(*(_x)) + sizeof((_x)->Data[0])*_cap); \
|
||||||
|
assert(temp != NULL); \
|
||||||
|
if((_x)) \
|
||||||
|
memcpy(((ALubyte*)temp)+sizeof(*(_x)), (_x)->Data, \
|
||||||
|
sizeof((_x)->Data[0])*old_size); \
|
||||||
|
\
|
||||||
|
al_free((_x)); \
|
||||||
|
(_x) = temp; \
|
||||||
|
(_x)->Capacity = _cap; \
|
||||||
|
} \
|
||||||
|
(_x)->Size = _size; \
|
||||||
|
} while(0) \
|
||||||
|
|
||||||
#define VECTOR_CAPACITY(_x) ((_x) ? (_x)->Capacity : 0)
|
#define VECTOR_CAPACITY(_x) ((_x) ? (_x)->Capacity : 0)
|
||||||
#define VECTOR_SIZE(_x) ((_x) ? (_x)->Size : 0)
|
#define VECTOR_SIZE(_x) ((_x) ? (_x)->Size : 0)
|
||||||
@ -44,8 +64,11 @@ ALboolean vector_resize(char *ptr, size_t base_size, size_t obj_size, size_t obj
|
|||||||
#define VECTOR_BEGIN(_x) ((_x) ? (_x)->Data + 0 : NULL)
|
#define VECTOR_BEGIN(_x) ((_x) ? (_x)->Data + 0 : NULL)
|
||||||
#define VECTOR_END(_x) ((_x) ? (_x)->Data + (_x)->Size : NULL)
|
#define VECTOR_END(_x) ((_x) ? (_x)->Data + (_x)->Size : NULL)
|
||||||
|
|
||||||
#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), VECTOR_SIZE(_x)+1, AL_FALSE) && \
|
#define VECTOR_PUSH_BACK(_x, _obj) do { \
|
||||||
(((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
|
size_t _pbsize = VECTOR_SIZE(_x)+1; \
|
||||||
|
VECTOR_RESIZE(_x, _pbsize, _pbsize); \
|
||||||
|
(_x)->Data[(_x)->Size-1] = (_obj); \
|
||||||
|
} while(0)
|
||||||
#define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
|
#define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
|
||||||
|
|
||||||
#define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
|
#define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user