Commits

Sebastian Hubbard  committed 08d6183 Draft

in for a penny, in for a pound

  • Participants
  • Parent commits 65067a7

Comments (0)

Files changed (1)

   return _amt_delete(AMT_MARSHAL(t), AMT_MARSHAL(r), key, len);
 }
 
+#define FIND_START				\
+  int ks;					\
+						\
+  if (!r)					\
+    return 0;					\
+						\
+  while (len) {					\
+  ks = r->keysize;				\
+  void *n;
+
 #define FIND_CAMT							\
   if (ks > 1) {								\
     if (len < ks)							\
   --len;					\
   }						
 
+#define FIND_END				\
+    r = n;					\
+  }						
+
 void *amt_find(amtnode * restrict r, unsigned char *key, int len) {
-  int ks;
-
-  if (!r)
-    return 0;
-
-  while (len) {
-    ks = r->keysize;
-    void *n;
-    
+  FIND_START;
+  
 #ifdef WITH_CAMT
-    FIND_CAMT;
+  FIND_CAMT;
 #endif
-    FIND_NEXT;
-    r = n;
-  }
+  FIND_NEXT;
+  FIND_END;
   
   if (r && r->keysize == 1 && r->item)
     return AMT_UNMARSHAL(r->item);
 }
 
 void amt_find_all(amtnode *r, unsigned char *key, int len, vbuffer *results) {
-  int ks;
-
-  if (!r)
-    return;
-
-  while (len) {
-    ks = r->keysize;
-    void *n;
-    
+  FIND_START;
+  
 #ifdef WITH_CAMT
-    FIND_CAMT;
+  FIND_CAMT;
 #endif
-    if (ks == 1 && r->item)
-      vbuffer_push_ptr(results, AMT_UNMARSHAL(r->item));
-    
-    FIND_NEXT;
-    r = n;
-  }
-
+  
+  if (ks == 1 && r->item)
+    vbuffer_push_ptr(results, AMT_UNMARSHAL(r->item));
+  
+  FIND_NEXT;
+  FIND_END;
+  
   if (r && r->keysize == 1 && r->item)
     vbuffer_push_ptr(results, AMT_UNMARSHAL(r->item));
 }