Skip to content

Commit b065b3d

Browse files
committed
Global: optimises usage of FFstrbuf and FFlist
1 parent 1337525 commit b065b3d

6 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/common/FFlist.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,10 @@ static inline void ffListClear(FFlist* list)
126126
assert(sizeof(itemType) == (listVar).elementSize); \
127127
(itemType*) ffListAdd(&(listVar)); \
128128
})
129+
130+
#define FF_LIST_FIRST(itemType, listVar) FF_LIST_GET(itemType, listVar, 0)
131+
#define FF_LIST_LAST(itemType, listVar) \
132+
({ \
133+
assert((listVar).length > 0); \
134+
FF_LIST_GET(itemType, listVar, ((listVar).length - 1)); \
135+
})

src/detection/dns/dns_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const char* ffDetectDNS(FFDNSOptions* options, FFlist* results)
7575
// Handle different DNS management services
7676
if (results->length == 1)
7777
{
78-
const FFstrbuf* firstEntry = FF_LIST_GET(FFstrbuf, *results, 0);
78+
const FFstrbuf* firstEntry = FF_LIST_FIRST(FFstrbuf, *results);
7979

8080
if (ffStrbufEqualS(firstEntry, "127.0.0.53"))
8181
{

src/detection/localip/localip_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
462462
appendIpv4(options, &item->ipv4, ifa);
463463
else if (adapter->ipv4.length > 0)
464464
{
465-
appendIpv4(options, &item->ipv4, *FF_LIST_GET(struct ifaddrs*, adapter->ipv4, 0));
465+
appendIpv4(options, &item->ipv4, *FF_LIST_FIRST(struct ifaddrs*, adapter->ipv4));
466466
FF_DEBUG("Using first IPv4 address for interface %s", adapter->mac->ifa_name);
467467
}
468468
}
@@ -527,7 +527,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
527527
appendIpv6(options, &item->ipv6, selected);
528528
else if (adapter->ipv6.length > 0)
529529
{
530-
appendIpv6(options, &item->ipv6, *FF_LIST_GET(struct ifaddrs*, adapter->ipv6, 0));
530+
appendIpv6(options, &item->ipv6, *FF_LIST_FIRST(struct ifaddrs*, adapter->ipv6));
531531
FF_DEBUG("Using first IPv6 address for interface %s", adapter->mac->ifa_name);
532532
}
533533
}

src/detection/packages/packages_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static uint32_t getAMUser(void)
261261
if (instance.state.platform.configDirs.length == 0) return 0;
262262

263263
// check if $XDG_CONFIG_HOME/appman/appman-config exists
264-
FFstrbuf* baseDir = FF_LIST_GET(FFstrbuf, instance.state.platform.configDirs, 0);
264+
FFstrbuf* baseDir = FF_LIST_FIRST(FFstrbuf, instance.state.platform.configDirs);
265265
uint32_t baseLen = baseDir->length;
266266
ffStrbufAppendS(baseDir, "appman/appman-config");
267267
FF_STRBUF_AUTO_DESTROY packagesPath = ffStrbufCreate();

src/fastfetch.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ static void generateConfigFile(bool force, const char* filePath, bool fullConfig
442442
exit(477);
443443
}
444444

445-
ffStrbufSet(&instance.state.genConfigPath, FF_LIST_GET(FFstrbuf, instance.state.platform.configDirs, 0));
445+
FFstrbuf* configDir = FF_LIST_FIRST(FFstrbuf, instance.state.platform.configDirs);
446+
ffStrbufEnsureFixedLengthFree(&instance.state.genConfigPath, configDir->length + strlen("fastfetch/config.jsonc"));
447+
ffStrbufSet(&instance.state.genConfigPath, configDir);
446448
ffStrbufAppendS(&instance.state.genConfigPath, "fastfetch/config.jsonc");
447449
}
448450
else
@@ -486,7 +488,8 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
486488

487489
//Try to load as an absolute path
488490

489-
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateS(value);
491+
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
492+
ffStrbufSetS(&absolutePath, value);
490493
bool strictJson = ffStrbufEndsWithIgnCaseS(&absolutePath, ".json");
491494
bool jsonc = !strictJson && ffStrbufEndsWithIgnCaseS(&absolutePath, ".jsonc");
492495
bool json5 = !strictJson && !jsonc && ffStrbufEndsWithIgnCaseS(&absolutePath, ".json5");

src/logo/logo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ static bool updateLogoPath(void)
487487
return true;
488488
}
489489

490-
FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreate();
490+
FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreateA(128);
491491
if (ffPathExpandEnv(options->source.chars, &fullPath) && ffPathExists(fullPath.chars, FF_PATHTYPE_FILE))
492492
{
493493
ffStrbufDestroy(&options->source);

0 commit comments

Comments
 (0)