]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Shortcut fstrcmp computations by taking into account the best known match so
authorBruno Haible <bruno@clisp.org>
Sun, 14 Sep 2008 21:41:30 +0000 (21:41 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:50 +0000 (12:15 +0200)
far.

gettext-tools/src/ChangeLog
gettext-tools/src/message.c
gettext-tools/src/message.h
gettext-tools/src/msgl-fsearch.c
gettext-tools/src/msgmerge.c

index 15ed384b9b98b6bf6ce84a9a63652d0aaf332c43..68c2600303dff27c3afff357bb2045ed82780e57 100644 (file)
@@ -1,3 +1,15 @@
+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>
 
index cfe808a35923aa3b368db743635ce7e6029aae6b..75fae5e0bb53f65d4e27dcc21675f4ed7a122a00 100644 (file)
@@ -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;
index d58b0a54a8b44c063be70d4361474003c2815d81..763ef34a581e95a94a6892ce70f74eec9f7a4b92 100644 (file)
@@ -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>
 
@@ -317,10 +317,13 @@ extern message_ty *
 
 
 /* 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.  */
index 1935a86c13aae5596ea11bce6cc33ed2277811d0..8d7d5410e3f73a9432ff81b8123b22cdfe076ec4 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -553,7 +553,8 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
                      {
                        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)
                          {
@@ -598,7 +599,8 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
        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)
              {
index d9d9676b623d680a17255160b22661543038d61a..576e0c3fdf7dc362df7529647427ad1d381e3ee9 100644 (file)
@@ -776,8 +776,8 @@ definitions_search_fuzzy (definitions_ty *definitions,
       /* 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;
     }