far.
+2008-09-14 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+ Bruno Haible <bruno@clisp.org>
+
+ * message.h (fuzzy_search_goal_function): Add 'lower_bound' argument.
+ * message.c (fuzzy_search_goal_function): Likewise. Use fstrcmp_bounded
+ instead of fstrcmp.
+ (message_list_search_fuzzy_inner): Pass fuzzy_search_goal_function the
+ best weight known so far, to shortcut computations.
+ * msgl-fsearch.c (message_fuzzy_index_search): Likewise.
+ * msgmerge.c (definitions_search_fuzzy): Update
+ fuzzy_search_goal_function calls.
+
2008-09-14 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
Bruno Haible <bruno@clisp.org>
/* 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>
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;
+ }
}
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;
/* 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>
/* The goal function used in fuzzy search.
- Higher values indicate a closer match. */
+ Higher values indicate a closer match.
+ If the result is < LOWER_BOUND, an arbitrary other value < LOWER_BOUND can
+ be returned. */
extern double
fuzzy_search_goal_function (const message_ty *mp,
- const char *msgctxt, const char *msgid);
+ const char *msgctxt, const char *msgid,
+ double lower_bound);
/* The threshold for fuzzy-searching.
A message is considered only if fstrcmp (msg, given) > FUZZY_THRESHOLD. */
/* Fast fuzzy searching among messages.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2008 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2006.
This program is free software: you can redistribute it and/or modify
{
message_ty *mp = findex->messages[ptr->index];
double weight =
- fuzzy_search_goal_function (mp, msgctxt, msgid);
+ fuzzy_search_goal_function (mp, msgctxt, msgid,
+ best_weight);
if (weight > best_weight)
{
for (j = 0; j < mlp->nitems; j++)
{
message_ty *mp = mlp->item[j];
- double weight = fuzzy_search_goal_function (mp, msgctxt, msgid);
+ double weight =
+ fuzzy_search_goal_function (mp, msgctxt, msgid, best_weight);
if (weight > best_weight)
{
/* Choose the best among mp1, mp2. */
if (mp1 == NULL
|| (mp2 != NULL
- && (fuzzy_search_goal_function (mp2, msgctxt, msgid)
- > fuzzy_search_goal_function (mp1, msgctxt, msgid))))
+ && (fuzzy_search_goal_function (mp2, msgctxt, msgid, 0.0)
+ > fuzzy_search_goal_function (mp1, msgctxt, msgid, 0.0))))
mp1 = mp2;
}