Welcome to the CHICKEN Scheme pasting service

string-ci comparison pasted by mario-goulart on Wed Sep 26 22:32:49 2012

(use srfi-13)

(define-syntax repeat
  (syntax-rules ()
    ((_ n forms ...)
     (let loop ((i n))
       (unless (zero? i)
         forms ...
         (loop (- i 1)))))))

(define big-string
  "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssfoossssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss")

(print "string-ci=? (from data-structures unit)")
(time (repeat 300000 (string-ci=? big-string big-string)))

(print "\nstring-ci= (from SRFI-13)")
(time (repeat 300000 (string-ci= big-string big-string)))


;;; On my system:

;; $ csi -s string-compare-ci.scm
;; string-ci=? (from data-structures unit)
;; 2.964s CPU time, 0.004s GC time (major), 16 mutations, 12/2738 GCs (major/minor)
;;
;; string-ci= (from SRFI-13)
;; 0.332s CPU time, 0.04s GC time (major), 16 mutations, 51/10623 GCs (major/minor)

patch for C_i_string_ci_equal_p added by mario-goulart on Wed Sep 26 22:51:23 2012

$ git diff runtime.c
diff --git a/runtime.c b/runtime.c
index 2673d81..7186f93 100644
--- a/runtime.c
+++ b/runtime.c
@@ -4392,7 +4392,7 @@ C_regparm C_word C_fcall C_i_string_equal_p(C_word x, C_word y)
 
 C_regparm C_word C_fcall C_i_string_ci_equal_p(C_word x, C_word y)
 {
-  C_word n;
+  C_word nx, ny;
   char *p1, *p2;
 
   if(C_immediatep(x) || C_header_bits(x) != C_STRING_TYPE)
@@ -4401,14 +4401,18 @@ C_regparm C_word C_fcall C_i_string_ci_equal_p(C_word x, C_word y)
   if(C_immediatep(y) || C_header_bits(y) != C_STRING_TYPE)
     barf(C_BAD_ARGUMENT_TYPE_ERROR, "string-ci=?", y);
 
-  n = C_header_size(x);
+  nx = C_header_size(x);
+  ny = C_header_size(y);
 
-  if(n != C_header_size(y)) return C_SCHEME_FALSE;
+  if(nx != ny) return C_SCHEME_FALSE;
+
+  if(C_memcmp((char *)C_data_pointer(x), (char *)C_data_pointer(y), nx))
+    return C_SCHEME_TRUE;
 
   p1 = (char *)C_data_pointer(x);
   p2 = (char *)C_data_pointer(y);
 
-  while(n--) {
+  while(nx--) {
     if(C_tolower((int)(*(p1++))) != C_tolower((int)(*(p2++))))
       return C_SCHEME_FALSE;
   }

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the procedure to access a character in a string by index in R5RS?
Visually impaired? Let me spell it for you (wav file) download WAV