Repository: fastfetch-cli/fastfetch
File: src/modules/terminalfont.c (C)

Code before:
{
    static const char* fontName = NULL;
    static const char* defaultProfile = NULL;
    static FFstrbuf key;
    static FFvariant res;
    res.strValue = NULL;
    ffStrbufInitAS(&key, 64, "/com/gexperts/Tilix/profiles/");

    defaultProfile = (ffSettingsGetGsettings(instance, "com.gexperts.Tilix.ProfilesList", NULL, "default", FF_VARIANT_TYPE_STRING)).strValue;

    if (!defaultProfile)
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Default\" profile in Tilix settings");
        ffStrbufDestroy(&key);
        return;
    }
    else
    {
        ffStrbufAppendS(&key, defaultProfile);
        ffStrbufAppendS(&key, "/use-system-font");

        res = ffSettingsGetDConf(instance,key.chars, FF_VARIANT_TYPE_BOOL);

        if(res.boolValueSet && res.boolValue == 0) // custom font
        {
            ffStrbufRemoveStrings(&key, 1, "/use-system-font");
            ffStrbufAppendS(&key, "/font");
            fontName = (ffSettingsGetDConf(instance, key.chars, FF_VARIANT_TYPE_STRING)).strValue;
        }
        else if(!res.boolValueSet || res.boolValue == 1) // system font
            fontName = (ffSettingsGetDConf(instance, "/org/gnome/desktop/interface/monospace-font-name", FF_VARIANT_TYPE_STRING)).strValue;
    }

    if (!fontName)
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Terminal font\" in Tilix settings");
        ffStrbufDestroy(&key);
        return;
    }

    printTerminalFont(instance, fontName);
    ffStrbufDestroy(&key);
}

static void printTTY(FFinstance* instance)
{
    FFstrbuf font;
    ffStrbufInit(&font);

    ffParsePropFile("/etc/vconsole.conf", "Font=%[^\n]", font.chars);
    ffStrbufRecalculateLength(&font);

Review comment (performance):
Removing strings is very slow. Maybe store the length of key before `ffStrbufAppendS(&key, "/use-system-font")` and use a `ffSubstrBefore` here.

Code after:
{
    const char* fontName = NULL;

    const char* defaultProfile = ffSettingsGetGsettings(instance, "com.gexperts.Tilix.ProfilesList", NULL, "default", FF_VARIANT_TYPE_STRING).strValue;

    if (!defaultProfile)
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Default\" profile in Tilix settings");
        return;
    }

    FFstrbuf key;
    ffStrbufInitAS(&key, 64, "/com/gexperts/Tilix/profiles/");
    ffStrbufAppendS(&key, defaultProfile);
    uint32_t keyLen = key.length;
    ffStrbufAppendS(&key, "/use-system-font");

    FFvariant res = ffSettingsGetDConf(instance,key.chars, FF_VARIANT_TYPE_BOOL);

    if(res.boolValueSet && !res.boolValue) // custom font
    {
        ffStrbufSubstrBefore(&key, keyLen);
        ffStrbufAppendS(&key, "/font");
        fontName = ffSettingsGetDConf(instance, key.chars, FF_VARIANT_TYPE_STRING).strValue;
    }
    else if(!res.boolValueSet || res.boolValue) // system font
        fontName = ffSettingsGetDConf(instance, "/org/gnome/desktop/interface/monospace-font-name", FF_VARIANT_TYPE_STRING).strValue;

    if (!fontName)
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Terminal font\" in Tilix settings");
        ffStrbufDestroy(&key);
        return;
    }

    printTerminalFont(instance, fontName);
    ffStrbufDestroy(&key);
}

static void printTTY(FFinstance* instance)
{
    FFstrbuf font;
    ffStrbufInit(&font);

    ffParsePropFile("/etc/vconsole.conf", "Font=%[^\n]", font.chars);
    ffStrbufRecalculateLength(&font);

    if(font.length == 0)
    {
        ffStrbufAppendS(&font, "VGA default kernel font ");
        ffProcessAppendStdOut(&font, (char* const[]){