postgres.git / summary / log / commit / refs

commit    2fb8da5a245661287833b05a1b2e275ddf83bbd7
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Sun Aug 30 00:11:56 2026 +0000

    Drop the per-entry copy of the flag mode in CompoundAffixFlags.
    
    Each CompoundAffixFlag carried its own copy of the dictionary's flag
    mode, which decides whether the union holds a string or an integer.
    The comment on the field explained why: cmpcmdflag() needs the mode,
    and at the time there was no bsearch() variant that would allow
    passing that context through.  But that problem is long gone, so let's
    remove the redundant storage.  No flexibility is lost because things
    would not work anyway if different flags within a dictionary have
    different representations; and the preceding commit has seen to it
    that they can't.  At present, this saves no storage on 64-bit machines
    because of alignment issues, but it still seems like good
    simplification.
    
    No back-patch: there's little value in this except cleanliness, and
    although probably no outside code is looking at this data structure,
    this'd be an API/ABI break if any does.
    
    Author: Ewan Young <kdbase.hack@gmail.com>
    Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
    Discussion: https://postgr.es/m/CAON2xHN3QmsaySM6DGWa1gttcbJoFh0wjAE-_ZpSPo=LKN1hYw@mail.gmail.com


src/backend/tsearch/spell.c | 22 +++++++++------------- src/include/tsearch/dicts/spell.h | 6 ++---- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c index dc4949042b8..f2c6e064218 100644 --- a/src/backend/tsearch/spell.c +++ b/src/backend/tsearch/spell.c @@ -208,14 +208,13 @@ cmpspellaffix(const void *s1, const void *s2) } static int -cmpcmdflag(const void *f1, const void *f2) +cmpcmdflag(const void *f1, const void *f2, void *arg) { const CompoundAffixFlag *fv1 = f1; const CompoundAffixFlag *fv2 = f2; + FlagMode flagMode = *(const FlagMode *) arg; - Assert(fv1->flagMode == fv2->flagMode); - - if (fv1->flagMode == FM_NUM) + if (flagMode == FM_NUM) { if (fv1->flag.i == fv2->flag.i) return 0; @@ -1071,7 +1070,6 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry, else entry->flag.s = cpstrdup(Conf, s); - entry->flagMode = Conf->flagMode; entry->value = val; } @@ -1135,7 +1133,7 @@ addCompoundAffixFlagValue(IspellDict *Conf, const char *s, uint32 val) * how flags are spelled may appear anywhere in the affix file, including * after the compound flags themselves, so the final representation cannot * be chosen until the whole file has been read. See - * finalizeCompoundAffixFlags(), which fills in flagMode as well. + * finalizeCompoundAffixFlags(). * * The interim copy goes in the short-lived build context, since the final * representation may well not be a string at all. @@ -1173,8 +1171,6 @@ finalizeCompoundAffixFlags(IspellDict *Conf) entry->flag.i = parseNumericAffixFlag(entry->flag.s); else entry->flag.s = cpstrdup(Conf, entry->flag.s); - - entry->flagMode = Conf->flagMode; } } @@ -1201,9 +1197,9 @@ getCompoundAffixFlagValue(IspellDict *Conf, const char *s) setCompoundAffixFlagValue(Conf, &key, sflag, 0); found = (CompoundAffixFlag *) - bsearch(&key, Conf->CompoundAffixFlags, - Conf->nCompoundAffixFlag, sizeof(CompoundAffixFlag), - cmpcmdflag); + bsearch_arg(&key, Conf->CompoundAffixFlags, + Conf->nCompoundAffixFlag, sizeof(CompoundAffixFlag), + cmpcmdflag, &Conf->flagMode); if (found != NULL) flag |= found->value; } @@ -1358,8 +1354,8 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename) finalizeCompoundAffixFlags(Conf); if (Conf->nCompoundAffixFlag > 1) - qsort(Conf->CompoundAffixFlags, Conf->nCompoundAffixFlag, - sizeof(CompoundAffixFlag), cmpcmdflag); + qsort_arg(Conf->CompoundAffixFlags, Conf->nCompoundAffixFlag, + sizeof(CompoundAffixFlag), cmpcmdflag, &Conf->flagMode); if (!tsearch_readline_begin(&trst, filename)) ereport(ERROR, diff --git a/src/include/tsearch/dicts/spell.h b/src/include/tsearch/dicts/spell.h index 038b4384fb4..7ca7e6fe69f 100644 --- a/src/include/tsearch/dicts/spell.h +++ b/src/include/tsearch/dicts/spell.h @@ -169,13 +169,11 @@ typedef struct CompoundAffixFlag { union { - /* Flag name if flagMode is FM_CHAR or FM_LONG */ + /* Flag name if the dictionary's flagMode is FM_CHAR or FM_LONG */ const char *s; - /* Flag name if flagMode is FM_NUM */ + /* Flag number if the dictionary's flagMode is FM_NUM */ uint32 i; } flag; - /* we don't have a bsearch_arg version, so, copy FlagMode */ - FlagMode flagMode; uint32 value; } CompoundAffixFlag; [parent: 15ee73d7d7cd]