this should improve some performance

This commit is contained in:
Nishi 2026-09-23 14:07:21 +09:00
commit feab74e968

View file

@ -72,23 +72,110 @@ int yomicmp(SJ4_CONTEXT u_char* ptr1, u_char* ptr2, u_char* saml) {
return MATCH; return MATCH;
} }
static __inline int yomicmp_seg(SJ4_CONTEXT u_char* ptr1, u_char* ptr2, u_char* saml, const u_char* segidx, int segidxlen) {
int i, j;
int same;
same = *saml;
i = getplen(ptr2);
j = getnlen(ptr2);
if(j == 0) {
ptr2 = (u_char*)segidx;
for(i = same; i; i--)
if(*ptr1++ != *ptr2++) return OVER;
j = segidxlen - same;
ptr2 = (u_char*)ptr2;
}
else if(i > same)
return CONT;
else {
if(i < same) same = i;
ptr1 += same;
ptr2 += DOUONBLKSIZENUMBER;
}
while(j-- > 0) {
if(*ptr1 > *ptr2) {
*saml = same;
return CONT;
} else if(*ptr1++ < *ptr2++) {
return OVER;
}
same++;
}
*saml = same;
return MATCH;
}
static __inline TypeDicSeg
srchidx_loaded(SJ4_CONTEXT TypeDicSeg low, int len) {
TypeDicSeg high;
TypeDicSeg mid;
int cmp;
u_char* target;
if((high = curdict->segunit - 1) < 1) return 0;
if(low == (TypeDicSeg)-1) low = 0;
while(low <= high) {
mid = (low + high) >> 1;
target = idxbuf + idxofs[mid];
cmp = istrcmp(cnvstart, target, len, sstrlen(target));
if(cmp == OVER) {
high = mid - 1;
}
else if(cmp != MATCH) {
low = mid + 1;
}
else {
return mid;
}
}
return (cmp == OVER && mid != DICSEGBASE) ? mid - 1 : mid;
}
u_char* u_char*
srchdict(SJ4_CONTEXT u_char* tagp) { srchdict(SJ4_CONTEXT u_char* tagp) {
TypeDicSeg segno; TypeDicSeg segno;
int cmp; int cmp;
int maxlen; int maxlen;
u_char* segidx = NULL;
int segidxlen = 0;
if(prevseg != (TypeDicSeg)-1){
segidx = idxbuf + idxofs[prevseg];
segidxlen = sstrlen(segidx);
}
maxlen = (cnvlen > MAXWDYOMILEN) ? MAXWDYOMILEN : cnvlen; maxlen = (cnvlen > MAXWDYOMILEN) ? MAXWDYOMILEN : cnvlen;
while((int)dicinl <= maxlen) { while((int)dicinl <= maxlen) {
segno = srchidx(SJ4_CONTEXT_PASS prevseg, (int)dicinl); segno = srchidx_loaded(SJ4_CONTEXT_PASS prevseg, (int)dicinl);
(*curdict->getdic)(SJ4_CONTEXT_PASS curdict, segno); (*curdict->getdic)(SJ4_CONTEXT_PASS curdict, segno);
if(prevseg != segno) { if(prevseg != segno) {
(*curdict->getdic)(SJ4_CONTEXT_PASS curdict, segno);
prevseg = segno; prevseg = segno;
segidx = idxbuf + idxofs[segno];
segidxlen = sstrlen(segidx);
tagp = dicbuf; tagp = dicbuf;
} }
@ -104,19 +191,20 @@ srchdict(SJ4_CONTEXT u_char* tagp) {
if(segno >= curdict->segunit) return NULL; if(segno >= curdict->segunit) return NULL;
(*curdict->getdic)(SJ4_CONTEXT_PASS curdict, segno); (*curdict->getdic)(SJ4_CONTEXT_PASS curdict, segno);
segidx = idxbuf + idxofs[segno];
segidxlen = sstrlen(segidx);
tagp = dicbuf; tagp = dicbuf;
} }
} }
if(tagp == dicbuf) { if(tagp == dicbuf) {
get_askknj(SJ4_CONTEXT_PASS2);
tagp += *tagp + 1; tagp += *tagp + 1;
} }
while(!segend(tagp)) { while(!segend(tagp)) {
cmp = yomicmp(SJ4_CONTEXT_PASS cnvstart, tagp, &dicsaml); cmp = yomicmp_seg(SJ4_CONTEXT_PASS cnvstart, tagp, &dicsaml, segidx, segidxlen);
if((int)dicsaml > maxlen) return NULL; if((int)dicsaml > maxlen) return NULL;
@ -131,6 +219,7 @@ srchdict(SJ4_CONTEXT u_char* tagp) {
else { else {
dicinl = dicsaml + 1; dicinl = dicsaml + 1;
if(askbase != dicbuf) get_askknj(SJ4_CONTEXT_PASS2);
return tagp; return tagp;
} }
} }