mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
more efficient memory usage
This commit is contained in:
+5
-3
@@ -134,7 +134,7 @@ static const FFstrbuf* getCacheDir(FFinstance* instance)
|
||||
if(init)
|
||||
return &cacheDir;
|
||||
|
||||
ffStrbufInitS(&cacheDir, getenv("XDG_CACHE_HOME"));
|
||||
ffStrbufInitAS(&cacheDir, 64, getenv("XDG_CACHE_HOME"));
|
||||
|
||||
if(cacheDir.length == 0)
|
||||
{
|
||||
@@ -161,7 +161,8 @@ bool ffPrintCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* d
|
||||
ffStrbufAppend(&cacheFile, getCacheDir(instance));
|
||||
ffStrbufAppendS(&cacheFile, defKey);
|
||||
|
||||
FF_STRBUF_CREATE(value);
|
||||
FFstrbuf value;
|
||||
ffStrbufInitA(&value, 128);
|
||||
ffGetFileContent(cacheFile.chars, &value);
|
||||
|
||||
ffStrbufDestroy(&cacheFile);
|
||||
@@ -232,7 +233,8 @@ void ffParsePropFile(const char* fileName, const char* regex, char* buffer)
|
||||
|
||||
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer)
|
||||
{
|
||||
FF_STRBUF_CREATE(absolutePath);
|
||||
FFstrbuf absolutePath;
|
||||
ffStrbufInitA(&absolutePath, 64);
|
||||
ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendC(&absolutePath, '/');
|
||||
ffStrbufAppendS(&absolutePath, relativeFile);
|
||||
|
||||
+10
-6
@@ -624,7 +624,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
|
||||
static void parseConfigFile(FFinstance* instance, FFdata* data)
|
||||
{
|
||||
FF_STRBUF_CREATE(filename);
|
||||
FFstrbuf filename;
|
||||
ffStrbufInitA(&filename, 64);
|
||||
|
||||
const char* xdgConfig = getenv("XDG_CONFIG_HOME");
|
||||
if(xdgConfig == NULL)
|
||||
@@ -657,10 +658,12 @@ static void parseConfigFile(FFinstance* instance, FFdata* data)
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
|
||||
FFstrbuf line;
|
||||
ffStrbufInitA(&line, 128); //The default structure line needs this size
|
||||
|
||||
while ((read = getline(&lineStart, &len, file)) != -1)
|
||||
{
|
||||
FFstrbuf line;
|
||||
ffStrbufInitS(&line, lineStart);
|
||||
ffStrbufSetS(&line, lineStart);
|
||||
ffStrbufTrimRight(&line, '\n');
|
||||
ffStrbufTrim(&line, ' ');
|
||||
|
||||
@@ -698,9 +701,10 @@ static void parseConfigFile(FFinstance* instance, FFdata* data)
|
||||
}
|
||||
|
||||
parseOption(instance, data, line.chars, valueStart);
|
||||
ffStrbufDestroy(&line);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&line);
|
||||
|
||||
if(lineStart != NULL)
|
||||
free(lineStart);
|
||||
|
||||
@@ -833,8 +837,8 @@ int main(int argc, const char** argv)
|
||||
|
||||
FFdata data;
|
||||
ffValuestoreInit(&data.valuestore);
|
||||
ffStrbufInit(&data.structure);
|
||||
ffStrbufInitA(&data.logoName, 2048);
|
||||
ffStrbufInitA(&data.structure, 256);
|
||||
ffStrbufInit(&data.logoName);
|
||||
|
||||
parseConfigFile(&instance, &data);
|
||||
parseArguments(&instance, &data, argc, argv);
|
||||
|
||||
+3
-2
@@ -49,7 +49,7 @@ void ffPrintCPU(FFinstance* instance)
|
||||
fclose(cpuinfo);
|
||||
|
||||
FFstrbuf namePretty;
|
||||
ffStrbufInitA(&namePretty, 256);
|
||||
ffStrbufInitA(&namePretty, 64);
|
||||
ffStrbufAppendS(&namePretty, name);
|
||||
ffStrbufRemoveStrings(&namePretty, 11,
|
||||
"(R)", "(r)", "(TM)", "(tm)", " CPU", " FPU", " Processor", " Dual-Core", " Quad-Core", " Six-Core", " Eight-Core"
|
||||
@@ -66,7 +66,8 @@ void ffPrintCPU(FFinstance* instance)
|
||||
int numProcsOnline = get_nprocs();
|
||||
int numProcsAvailable = get_nprocs_conf();
|
||||
|
||||
FF_STRBUF_CREATE(cpu);
|
||||
FFstrbuf cpu;
|
||||
ffStrbufInitA(&cpu, 128);
|
||||
|
||||
if(instance->config.cpuFormat.length == 0)
|
||||
{
|
||||
|
||||
+2
-1
@@ -35,7 +35,8 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_
|
||||
char name[512];
|
||||
ffpci_lookup_name(pacc, name, sizeof(name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
|
||||
|
||||
FF_STRBUF_CREATE(gpu);
|
||||
FFstrbuf gpu;
|
||||
ffStrbufInitA(&gpu, 128);
|
||||
|
||||
if(instance->config.gpuFormat.length == 0)
|
||||
{
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define FASTFETCH_STRBUF_DEFAULT_ALLOC 64
|
||||
#define FASTFETCH_STRBUF_DEFAULT_ALLOC 32
|
||||
|
||||
typedef struct FFstrbuf
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user