Skip to content

Commit 7b877b3

Browse files
committed
patch 7.4.1064
Problem: When a spell file has single letter compounding creating suggestions takes an awful long time. Solution: Add th eNOCOMPOUNDSUGS flag.
1 parent 4d1c0a4 commit 7b877b3

3 files changed

Lines changed: 50 additions & 10 deletions

File tree

runtime/doc/spell.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,14 @@ the item name. Case is always ignored.
13861386

13871387
The Hunspell feature to use three arguments and flags is not supported.
13881388

1389+
*spell-NOCOMPOUNDSUGS*
1390+
This item indicates that using compounding to make suggestions is not a good
1391+
idea. Use this when compounding is used with very short or one-character
1392+
words. E.g. to make numbers out of digits. Without this flag creating
1393+
suggestions would spend most time trying all kind of weird compound words.
1394+
1395+
NOCOMPOUNDSUGS ~
1396+
13891397
*spell-SYLLABLE*
13901398
The SYLLABLE item defines characters or character sequences that are used to
13911399
count the number of syllables in a word. Example:

src/spell.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
# define SPELL_PRINTTREE
6060
#endif
6161

62+
/* Use SPELL_COMPRESS_ALLWAYS for debugging: compress the word tree after
63+
* adding a word. Only use it for small word lists! */
64+
#if 0
65+
# define SPELL_COMPRESS_ALLWAYS
66+
#endif
67+
6268
/* Use DEBUG_TRIEWALK to print the changes made in suggest_trie_walk() for a
6369
* specific word. */
6470
#if 0
@@ -177,6 +183,8 @@
177183
* <timestamp> 8 bytes time in seconds that must match with .sug file
178184
*
179185
* sectionID == SN_NOSPLITSUGS: nothing
186+
*
187+
* sectionID == SN_NOCOMPOUNDSUGS: nothing
180188
*
181189
* sectionID == SN_WORDS: <word> ...
182190
* <word> N bytes NUL terminated common word
@@ -501,6 +509,7 @@ struct slang_S
501509
garray_T sl_repsal; /* list of fromto_T entries from REPSAL lines */
502510
short sl_repsal_first[256]; /* sl_rep_first for REPSAL lines */
503511
int sl_nosplitsugs; /* don't suggest splitting a word */
512+
int sl_nocompoundsugs; /* don't suggest compounding */
504513

505514
/* Info from the .sug file. Loaded on demand. */
506515
time_t sl_sugtime; /* timestamp for .sug file */
@@ -570,6 +579,7 @@ typedef struct langp_S
570579
#define SN_WORDS 13 /* common words */
571580
#define SN_NOSPLITSUGS 14 /* don't split word for suggestions */
572581
#define SN_INFO 15 /* info section */
582+
#define SN_NOCOMPOUNDSUGS 16 /* don't compound for suggestions */
573583
#define SN_END 255 /* end of sections */
574584

575585
#define SNF_REQUIRED 1 /* <sectionflags>: required section */
@@ -2913,7 +2923,11 @@ spell_load_file(fname, lang, old_lp, silent)
29132923
break;
29142924

29152925
case SN_NOSPLITSUGS:
2916-
lp->sl_nosplitsugs = TRUE; /* <timestamp> */
2926+
lp->sl_nosplitsugs = TRUE;
2927+
break;
2928+
2929+
case SN_NOCOMPOUNDSUGS:
2930+
lp->sl_nocompoundsugs = TRUE;
29172931
break;
29182932

29192933
case SN_COMPOUND:
@@ -5005,6 +5019,7 @@ typedef struct spellinfo_S
50055019
char_u *si_sofoto; /* SOFOTO text */
50065020
int si_nosugfile; /* NOSUGFILE item found */
50075021
int si_nosplitsugs; /* NOSPLITSUGS item found */
5022+
int si_nocompoundsugs; /* NOCOMPOUNDSUGS item found */
50085023
int si_followup; /* soundsalike: ? */
50095024
int si_collapse; /* soundsalike: ? */
50105025
hashtab_T si_commonwords; /* hashtable for common words */
@@ -5130,9 +5145,9 @@ spell_print_node(wordnode_T *node, int depth)
51305145
PRINTSOME(line1, depth, "(%d)", node->wn_nr, 0);
51315146
PRINTSOME(line2, depth, " ", 0, 0);
51325147
PRINTSOME(line3, depth, " ", 0, 0);
5133-
msg(line1);
5134-
msg(line2);
5135-
msg(line3);
5148+
msg((char_u *)line1);
5149+
msg((char_u *)line2);
5150+
msg((char_u *)line3);
51365151
}
51375152
else
51385153
{
@@ -5158,9 +5173,9 @@ spell_print_node(wordnode_T *node, int depth)
51585173

51595174
if (node->wn_byte == NUL)
51605175
{
5161-
msg(line1);
5162-
msg(line2);
5163-
msg(line3);
5176+
msg((char_u *)line1);
5177+
msg((char_u *)line2);
5178+
msg((char_u *)line3);
51645179
}
51655180

51665181
/* do the children */
@@ -5598,6 +5613,10 @@ spell_read_aff(spin, fname)
55985613
{
55995614
spin->si_nosplitsugs = TRUE;
56005615
}
5616+
else if (is_aff_rule(items, itemcnt, "NOCOMPOUNDSUGS", 1))
5617+
{
5618+
spin->si_nocompoundsugs = TRUE;
5619+
}
56015620
else if (is_aff_rule(items, itemcnt, "NOSUGFILE", 1))
56025621
{
56035622
spin->si_nosugfile = TRUE;
@@ -7621,7 +7640,7 @@ tree_add_word(spin, word, root, flags, region, affixID)
76217640
node = *prev;
76227641
}
76237642
#ifdef SPELL_PRINTTREE
7624-
smsg("Added \"%s\"", word);
7643+
smsg((char_u *)"Added \"%s\"", word);
76257644
spell_print_tree(root->wn_sibling);
76267645
#endif
76277646

@@ -7647,7 +7666,7 @@ tree_add_word(spin, word, root, flags, region, affixID)
76477666
* (si_compress_cnt == 1) and the number of free nodes drops below the
76487667
* maximum word length.
76497668
*/
7650-
#ifndef SPELL_PRINTTREE
7669+
#ifndef SPELL_COMPRESS_ALLWAYS
76517670
if (spin->si_compress_cnt == 1
76527671
? spin->si_free_count < MAXWLEN
76537672
: spin->si_blocks_cnt >= compress_start)
@@ -8295,6 +8314,16 @@ write_vim_spell(spin, fname)
82958314
put_bytes(fd, (long_u)0, 4); /* <sectionlen> */
82968315
}
82978316

8317+
/* SN_NOCOMPUNDSUGS: nothing
8318+
* This is used to notify that no suggestions with compounds are to be
8319+
* made. */
8320+
if (spin->si_nocompoundsugs)
8321+
{
8322+
putc(SN_NOCOMPOUNDSUGS, fd); /* <sectionID> */
8323+
putc(0, fd); /* <sectionflags> */
8324+
put_bytes(fd, (long_u)0, 4); /* <sectionlen> */
8325+
}
8326+
82988327
/* SN_COMPOUND: compound info.
82998328
* We don't mark it required, when not supported all compound words will
83008329
* be bad words. */
@@ -11883,6 +11912,7 @@ suggest_trie_walk(su, lp, fword, soundfold)
1188311912
*/
1188411913
try_compound = FALSE;
1188511914
if (!soundfold
11915+
&& !slang->sl_nocompoundsugs
1188611916
&& slang->sl_compprog != NULL
1188711917
&& ((unsigned)flags >> 24) != 0
1188811918
&& sp->ts_twordlen - sp->ts_splitoff
@@ -11907,7 +11937,7 @@ suggest_trie_walk(su, lp, fword, soundfold)
1190711937

1190811938
/* For NOBREAK we never try splitting, it won't make any word
1190911939
* valid. */
11910-
if (slang->sl_nobreak)
11940+
if (slang->sl_nobreak && !slang->sl_nocompoundsugs)
1191111941
try_compound = TRUE;
1191211942

1191311943
/* If we could add a compound word, and it's also possible to

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1064,
744746
/**/
745747
1063,
746748
/**/

0 commit comments

Comments
 (0)