]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - correct.c
Cleaner transformation calls (one less size_t for agruments). We can coalesce it...
[xonotic/gmqcc.git] / correct.c
index 6e49def96241f94e69717b7ef09a7cb78b5bffe1..226579b4281dadee24f3629917feb645dd8b837e 100644 (file)
--- a/correct.c
+++ b/correct.c
@@ -318,7 +318,7 @@ static const char correct_alpha[] = "abcdefghijklmnopqrstuvwxyz"
  * need to take a size_t ** to carry it along (would all the argument
  * overhead be worth it?)  
  */
-static size_t correct_deletion(const char *ident, char **array, size_t index) {
+static size_t correct_deletion(const char *ident, char **array) {
     size_t       itr = 0;
     const size_t len = strlen(ident);
 
@@ -326,13 +326,13 @@ static size_t correct_deletion(const char *ident, char **array, size_t index) {
         char *a = (char*)correct_pool_alloc(len+1);
         memcpy(a, ident, itr);
         memcpy(a + itr, ident + itr + 1, len - itr);
-        array[index + itr] = a;
+        array[itr] = a;
     }
 
     return itr;
 }
 
-static size_t correct_transposition(const char *ident, char **array, size_t index) {
+static size_t correct_transposition(const char *ident, char **array) {
     size_t       itr = 0;
     const size_t len = strlen(ident);
 
@@ -343,13 +343,13 @@ static size_t correct_transposition(const char *ident, char **array, size_t inde
         tmp      = a[itr];
         a[itr  ] = a[itr+1];
         a[itr+1] = tmp;
-        array[index + itr] = a;
+        array[itr] = a;
     }
 
     return itr;
 }
 
-static size_t correct_alteration(const char *ident, char **array, size_t index) {
+static size_t correct_alteration(const char *ident, char **array) {
     size_t       itr = 0;
     size_t       jtr = 0;
     size_t       ktr = 0;
@@ -360,14 +360,14 @@ static size_t correct_alteration(const char *ident, char **array, size_t index)
             char *a = (char*)correct_pool_alloc(len+1);
             memcpy(a, ident, len+1);
             a[itr] = correct_alpha[jtr];
-            array[index + ktr] = a;
+            array[ktr] = a;
         }
     }
 
     return ktr;
 }
 
-static size_t correct_insertion(const char *ident, char **array, size_t index) {
+static size_t correct_insertion(const char *ident, char **array) {
     size_t       itr = 0;
     size_t       jtr = 0;
     size_t       ktr = 0;
@@ -379,7 +379,7 @@ static size_t correct_insertion(const char *ident, char **array, size_t index) {
             memcpy(a, ident, itr);
             memcpy(a + itr + 1, ident + itr, len - itr + 1);
             a[itr] = correct_alpha[jtr];
-            array[index + ktr] = a;
+            array[ktr] = a;
         }
     }
 
@@ -405,10 +405,10 @@ static char **correct_edit(const char *ident) {
     if (!find)
         return NULL;
 
-    next  = correct_deletion     (ident, find, 0);
-    next += correct_transposition(ident, findnext);
-    next += correct_alteration   (ident, findnext);
-    /*****/ correct_insertion    (ident, findnext);
+    next  = correct_deletion     (ident, find);
+    next += correct_transposition(ident, find+next);
+    next += correct_alteration   (ident, find+next);
+    /*****/ correct_insertion    (ident, find+next);
 
     return find;
 }
@@ -429,7 +429,7 @@ static int correct_exist(char **array, size_t rows, char *ident) {
      * cmpl %eax, %ebx      ; ebx = &LHS[END_POS]
      *
      * jbe correct_cmp_eq
-     * movb (%edx), %cl     ; micro-optimized on even atoms :-)
+     * movb (%edx), %cl     ; micro-optimized even on atoms :-)
      * cmpb %cl, (%eax)     ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      * jg  correct_cmp_gt
      * jge correct_cmp_loop
@@ -457,7 +457,7 @@ static int correct_exist(char **array, size_t rows, char *ident) {
 static GMQCC_INLINE char **correct_known_resize(char **res, size_t *allocated, size_t size) {
     size_t oldallocated = *allocated;
     char **out;
-    if (size+1 < oldallocated)
+    if (size < oldallocated)
         return res;
 
     out = correct_pool_alloc(sizeof(*res) * oldallocated + 32);
@@ -512,10 +512,7 @@ static char *correct_maximum(correct_trie_t* table, char **array, size_t rows) {
 /*
  * This is the exposed interface:
  * takes a table for the dictonary a vector of sizes (used for internal
- * probability calculation, and an identifier to "correct"
- *
- * the add function works the same.  Except the identifier is used to
- * add to the dictonary.  
+ * probability calculation), and an identifier to "correct".
  */
 char *correct_str(correct_trie_t* table, const char *ident) {
     char **e1      = NULL;