mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Global: optimises usage of FFstrbuf and FFlist
This commit is contained in:
@@ -126,3 +126,10 @@ static inline void ffListClear(FFlist* list)
|
||||
assert(sizeof(itemType) == (listVar).elementSize); \
|
||||
(itemType*) ffListAdd(&(listVar)); \
|
||||
})
|
||||
|
||||
#define FF_LIST_FIRST(itemType, listVar) FF_LIST_GET(itemType, listVar, 0)
|
||||
#define FF_LIST_LAST(itemType, listVar) \
|
||||
({ \
|
||||
assert((listVar).length > 0); \
|
||||
FF_LIST_GET(itemType, listVar, ((listVar).length - 1)); \
|
||||
})
|
||||
|
||||
@@ -75,7 +75,7 @@ const char* ffDetectDNS(FFDNSOptions* options, FFlist* results)
|
||||
// Handle different DNS management services
|
||||
if (results->length == 1)
|
||||
{
|
||||
const FFstrbuf* firstEntry = FF_LIST_GET(FFstrbuf, *results, 0);
|
||||
const FFstrbuf* firstEntry = FF_LIST_FIRST(FFstrbuf, *results);
|
||||
|
||||
if (ffStrbufEqualS(firstEntry, "127.0.0.53"))
|
||||
{
|
||||
|
||||
@@ -462,7 +462,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
|
||||
appendIpv4(options, &item->ipv4, ifa);
|
||||
else if (adapter->ipv4.length > 0)
|
||||
{
|
||||
appendIpv4(options, &item->ipv4, *FF_LIST_GET(struct ifaddrs*, adapter->ipv4, 0));
|
||||
appendIpv4(options, &item->ipv4, *FF_LIST_FIRST(struct ifaddrs*, adapter->ipv4));
|
||||
FF_DEBUG("Using first IPv4 address for interface %s", adapter->mac->ifa_name);
|
||||
}
|
||||
}
|
||||
@@ -527,7 +527,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
|
||||
appendIpv6(options, &item->ipv6, selected);
|
||||
else if (adapter->ipv6.length > 0)
|
||||
{
|
||||
appendIpv6(options, &item->ipv6, *FF_LIST_GET(struct ifaddrs*, adapter->ipv6, 0));
|
||||
appendIpv6(options, &item->ipv6, *FF_LIST_FIRST(struct ifaddrs*, adapter->ipv6));
|
||||
FF_DEBUG("Using first IPv6 address for interface %s", adapter->mac->ifa_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ static uint32_t getAMUser(void)
|
||||
if (instance.state.platform.configDirs.length == 0) return 0;
|
||||
|
||||
// check if $XDG_CONFIG_HOME/appman/appman-config exists
|
||||
FFstrbuf* baseDir = FF_LIST_GET(FFstrbuf, instance.state.platform.configDirs, 0);
|
||||
FFstrbuf* baseDir = FF_LIST_FIRST(FFstrbuf, instance.state.platform.configDirs);
|
||||
uint32_t baseLen = baseDir->length;
|
||||
ffStrbufAppendS(baseDir, "appman/appman-config");
|
||||
FF_STRBUF_AUTO_DESTROY packagesPath = ffStrbufCreate();
|
||||
|
||||
+5
-2
@@ -442,7 +442,9 @@ static void generateConfigFile(bool force, const char* filePath, bool fullConfig
|
||||
exit(477);
|
||||
}
|
||||
|
||||
ffStrbufSet(&instance.state.genConfigPath, FF_LIST_GET(FFstrbuf, instance.state.platform.configDirs, 0));
|
||||
FFstrbuf* configDir = FF_LIST_FIRST(FFstrbuf, instance.state.platform.configDirs);
|
||||
ffStrbufEnsureFixedLengthFree(&instance.state.genConfigPath, configDir->length + strlen("fastfetch/config.jsonc"));
|
||||
ffStrbufSet(&instance.state.genConfigPath, configDir);
|
||||
ffStrbufAppendS(&instance.state.genConfigPath, "fastfetch/config.jsonc");
|
||||
}
|
||||
else
|
||||
@@ -486,7 +488,8 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
|
||||
|
||||
//Try to load as an absolute path
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateS(value);
|
||||
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
|
||||
ffStrbufSetS(&absolutePath, value);
|
||||
bool strictJson = ffStrbufEndsWithIgnCaseS(&absolutePath, ".json");
|
||||
bool jsonc = !strictJson && ffStrbufEndsWithIgnCaseS(&absolutePath, ".jsonc");
|
||||
bool json5 = !strictJson && !jsonc && ffStrbufEndsWithIgnCaseS(&absolutePath, ".json5");
|
||||
|
||||
+1
-1
@@ -487,7 +487,7 @@ static bool updateLogoPath(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreateA(128);
|
||||
if (ffPathExpandEnv(options->source.chars, &fullPath) && ffPathExists(fullPath.chars, FF_PATHTYPE_FILE))
|
||||
{
|
||||
ffStrbufDestroy(&options->source);
|
||||
|
||||
Reference in New Issue
Block a user