From 2ff767368620da03140296fae5d2d8a319e01347 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 26 Jun 2022 12:02:15 -0700 Subject: [PATCH] gvplugin_load: use a 'strview_t' for 'typ' Slightly more readable and less error prone than doing this inline. --- lib/gvc/gvplugin.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index cfe441ffa..38b2b8711 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -281,17 +281,14 @@ gvplugin_available_t *gvplugin_load(GVC_t * gvc, api_t api, const char *str) /* iterate the linked list of plugins for this api */ for (pnext = gvc->apis[api]; pnext; pnext = pnext->next) { - const char *typ = pnext->typestr; - const char *typ_end = strchr(typ, ':'); - size_t typ_len = - typ_end == NULL ? strlen(typ) : (size_t)(typ_end - typ); + const strview_t typ = strview(pnext->typestr, ':'); strview_t dep = {NULL}; - if (typ_end != NULL) { - dep = strview(typ_end + strlen(":"), '\0'); + if (typ.data[typ.size] == ':') { + dep = strview(typ.data + typ.size + strlen(":"), '\0'); } - if (typ_len != reqtyp_len || strncmp(typ, reqtyp, reqtyp_len)) + if (typ.size != reqtyp_len || strncmp(typ.data, reqtyp, reqtyp_len)) continue; /* types empty or mismatched */ if (dep.data && reqdep.data) { if (!strview_eq(dep, reqdep)) { -- 2.40.0