Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a38321

Browse files
committed
Significant simplification of the code thanks to proper handling of compound affixes (local copy not needed anymore except for a few methods).
1 parentdfc0e45 commit4a38321

File tree

3 files changed

+41
-1346
lines changed

3 files changed

+41
-1346
lines changed

‎src/shared_ispell.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"libpq/md5.h"
2424

2525
#include"spell.h"
26+
#include"tsearch/dicts/spell.h"
2627

2728
#ifdefPG_MODULE_MAGIC
2829
PG_MODULE_MAGIC;
@@ -231,25 +232,25 @@ void init_shared_dict(DictInfo * info, char * dictFile, char * affFile, char * s
231232

232233
dict= (IspellDict*)palloc0(sizeof(IspellDict));
233234

234-
SharedNIStartBuild(dict);
235+
NIStartBuild(dict);
235236

236-
SharedNIImportDictionary(dict,
237+
NIImportDictionary(dict,
237238
get_tsearch_config_filename(dictFile,"dict"));
238239

239-
SharedNIImportAffixes(dict,
240+
NIImportAffixes(dict,
240241
get_tsearch_config_filename(affFile,"affix"));
241242

242-
SharedNISortDictionary(dict);
243-
SharedNISortAffixes(dict);
243+
NISortDictionary(dict);
244+
NISortAffixes(dict);
244245

245-
SharedNIFinishBuild(dict);
246+
NIFinishBuild(dict);
246247

247248
shdict=copyIspellDict(dict,dictFile,affFile);
248249

249250
shdict->next=segment_info->dict;
250251
segment_info->dict=shdict;
251252

252-
elog(LOG,"shared ispell init done, remaining %d B",segment_info->available);
253+
elog(LOG,"shared ispell init done, remaining %ld B",segment_info->available);
253254

254255
}
255256

@@ -602,10 +603,28 @@ SharedStopList * copyStopList(StopList * list, char * stopFile) {
602603
returncopy;
603604
}
604605

606+
static
607+
intcountCMPDAffixes(CMPDAffix*affixes) {
608+
609+
/* there's at least one affix */
610+
intcount=1;
611+
CMPDAffix*ptr=affixes;
612+
613+
/* the last one is marked with (affix == NULL) */
614+
while (ptr->affix)
615+
{
616+
ptr++;
617+
count++;
618+
}
619+
620+
returncount;
621+
622+
}
623+
605624
static
606625
SharedIspellDict*copyIspellDict(IspellDict*dict,char*dictFile,char*affixFile) {
607626

608-
inti;
627+
inti,cnt;
609628

610629
SharedIspellDict*copy= (SharedIspellDict*)shalloc(sizeof(SharedIspellDict));
611630

@@ -632,11 +651,10 @@ SharedIspellDict * copyIspellDict(IspellDict * dict, char * dictFile, char * aff
632651
strcpy(copy->AffixData[i],dict->AffixData[i]);
633652
}
634653

635-
/* copy compound affixes */
636-
/* FIXME How to copy this without the cmpaffixes? If we can get rid of this field, we
637-
* could get rid of the local IspellDict copy. */
638-
copy->CompoundAffix= (CMPDAffix*)shalloc(sizeof(CMPDAffix)*dict->cmpaffixes);
639-
memcpy(copy->CompoundAffix,dict->CompoundAffix,sizeof(CMPDAffix)*dict->cmpaffixes);
654+
/* copy compound affixes (there's at least one) */
655+
cnt=countCMPDAffixes(dict->CompoundAffix);
656+
copy->CompoundAffix= (CMPDAffix*)shalloc(sizeof(CMPDAffix)*cnt);
657+
memcpy(copy->CompoundAffix,dict->CompoundAffix,sizeof(CMPDAffix)*cnt);
640658

641659
memcpy(copy->flagval,dict->flagval,255);
642660
copy->usecompound=dict->usecompound;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp