summaryrefslogtreecommitdiffstats
path: root/src/glx
diff options
context:
space:
mode:
authorAdam Jackson <[email protected]>2019-08-14 12:14:06 -0400
committerAdam Jackson <[email protected]>2019-08-20 14:05:01 -0400
commit35fc7bdf0e6ad6547e39099e7060a3d89539b56d (patch)
treeea7cfc063ad89b9118b71343cf425ace2e288660 /src/glx
parent97d58eabcc87d9b66b5837eeae0ce1174d29f448 (diff)
glx: convert glx_config_create_list to one big calloc
Simpler, less failure prone, less malloc overhead, what's not to like. Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src/glx')
-rw-r--r--src/glx/glxconfig.c63
1 files changed, 26 insertions, 37 deletions
diff --git a/src/glx/glxconfig.c b/src/glx/glxconfig.c
index 87a02fa9b6b..003b5c8e6ed 100644
--- a/src/glx/glxconfig.c
+++ b/src/glx/glxconfig.c
@@ -218,54 +218,43 @@ glx_config_get(struct glx_config * mode, int attribute, int *value_return)
_X_HIDDEN struct glx_config *
glx_config_create_list(unsigned count)
{
- const size_t size = sizeof(struct glx_config);
- struct glx_config *base = NULL;
- struct glx_config **next;
+ struct glx_config *c = NULL;
unsigned i;
- next = &base;
- for (i = 0; i < count; i++) {
- *next = calloc(1, size);
- if (*next == NULL) {
- glx_config_destroy_list(base);
- base = NULL;
- break;
- }
+ if (!(c = calloc(count, sizeof(struct glx_config))))
+ return NULL;
- (*next)->visualID = GLX_DONT_CARE;
- (*next)->visualType = GLX_DONT_CARE;
- (*next)->visualRating = GLX_NONE;
- (*next)->transparentPixel = GLX_NONE;
- (*next)->transparentRed = GLX_DONT_CARE;
- (*next)->transparentGreen = GLX_DONT_CARE;
- (*next)->transparentBlue = GLX_DONT_CARE;
- (*next)->transparentAlpha = GLX_DONT_CARE;
- (*next)->transparentIndex = GLX_DONT_CARE;
- (*next)->xRenderable = GLX_DONT_CARE;
- (*next)->fbconfigID = GLX_DONT_CARE;
- (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML;
- (*next)->bindToTextureRgb = GLX_DONT_CARE;
- (*next)->bindToTextureRgba = GLX_DONT_CARE;
- (*next)->bindToMipmapTexture = GLX_DONT_CARE;
- (*next)->bindToTextureTargets = GLX_DONT_CARE;
- (*next)->yInverted = GLX_DONT_CARE;
- (*next)->sRGBCapable = GLX_DONT_CARE;
+ for (i = 0; i < count; i++) {
+ c[i].visualID = GLX_DONT_CARE;
+ c[i].visualType = GLX_DONT_CARE;
+ c[i].visualRating = GLX_NONE;
+ c[i].transparentPixel = GLX_NONE;
+ c[i].transparentRed = GLX_DONT_CARE;
+ c[i].transparentGreen = GLX_DONT_CARE;
+ c[i].transparentBlue = GLX_DONT_CARE;
+ c[i].transparentAlpha = GLX_DONT_CARE;
+ c[i].transparentIndex = GLX_DONT_CARE;
+ c[i].xRenderable = GLX_DONT_CARE;
+ c[i].fbconfigID = GLX_DONT_CARE;
+ c[i].swapMethod = GLX_SWAP_UNDEFINED_OML;
+ c[i].bindToTextureRgb = GLX_DONT_CARE;
+ c[i].bindToTextureRgba = GLX_DONT_CARE;
+ c[i].bindToMipmapTexture = GLX_DONT_CARE;
+ c[i].bindToTextureTargets = GLX_DONT_CARE;
+ c[i].yInverted = GLX_DONT_CARE;
+ c[i].sRGBCapable = GLX_DONT_CARE;
- next = &((*next)->next);
+ if (i != count -1)
+ c[i].next = &(c[i+1]);
}
- return base;
+ return c;
}
_X_HIDDEN void
glx_config_destroy_list(struct glx_config *configs)
{
- while (configs != NULL) {
- struct glx_config *const next = configs->next;
-
- free(configs);
- configs = next;
- }
+ free(configs);
}