diff options
author | Bruno Haible <bruno@clisp.org> | 2008-09-14 21:41:30 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:15:50 +0200 |
commit | 2df5c44aa8b410ec9ff638ed6de8c2fc334f14ab (patch) | |
tree | f688414d0ceafa84046be481f605e796137d0073 /gettext-tools/src/message.c | |
parent | 49d06a1ec3bf7dfc3a33c8c0fe375a3702e9593a (diff) | |
download | external_gettext-2df5c44aa8b410ec9ff638ed6de8c2fc334f14ab.zip external_gettext-2df5c44aa8b410ec9ff638ed6de8c2fc334f14ab.tar.gz external_gettext-2df5c44aa8b410ec9ff638ed6de8c2fc334f14ab.tar.bz2 |
Shortcut fstrcmp computations by taking into account the best known match so
far.
Diffstat (limited to 'gettext-tools/src/message.c')
-rw-r--r-- | gettext-tools/src/message.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index cfe808a..75fae5e 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2007 Free Software Foundation, Inc. + Copyright (C) 1995-1998, 2000-2008 Free Software Foundation, Inc. This file was written by Peter Miller <millerp@canb.auug.org.au> @@ -531,22 +531,37 @@ message_list_search (message_list_ty *mlp, double fuzzy_search_goal_function (const message_ty *mp, - const char *msgctxt, const char *msgid) -{ - /* The use of 'volatile' guarantees that excess precision bits are dropped - before the addition and before the following comparison at the caller's - site. It is necessary on x86 systems where double-floats are not IEEE - compliant by default, to avoid that msgmerge results become platform and - compiler option dependent. 'volatile' is a portable alternative to gcc's - -ffloat-store option. */ - volatile double weight = fstrcmp (msgid, mp->msgid); + const char *msgctxt, const char *msgid, + double lower_bound) +{ + double bonus = 0.0; /* A translation for a context is a good proposal also for another. But give mp a small advantage if mp is valid regardless of any context or has the same context as the one being looked up. */ if (mp->msgctxt == NULL || (msgctxt != NULL && strcmp (msgctxt, mp->msgctxt) == 0)) - weight += 0.00001; - return weight; + { + bonus = 0.00001; + /* Since we will consider (weight + bonus) at the end, we are only + interested in weights that are >= lower_bound - bonus. Subtract + a little more than the bonus, in order to avoid trouble due to + rounding errors. */ + lower_bound -= bonus * 1.01; + } + + { + /* The use of 'volatile' guarantees that excess precision bits are dropped + before the addition and before the following comparison at the caller's + site. It is necessary on x86 systems where double-floats are not IEEE + compliant by default, to avoid that msgmerge results become platform and + compiler option dependent. 'volatile' is a portable alternative to + gcc's -ffloat-store option. */ + volatile double weight = fstrcmp_bounded (msgid, mp->msgid, lower_bound); + + weight += bonus; + + return weight; + } } @@ -567,7 +582,8 @@ message_list_search_fuzzy_inner (message_list_ty *mlp, if (mp->msgstr != NULL && mp->msgstr[0] != '\0') { - double weight = fuzzy_search_goal_function (mp, msgctxt, msgid); + double weight = + fuzzy_search_goal_function (mp, msgctxt, msgid, *best_weight_p); if (weight > *best_weight_p) { *best_weight_p = weight; |