[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optimizing ‘string=’
From: |
Ludovic Courtès |
Subject: |
Re: Optimizing ‘string=’ |
Date: |
Tue, 22 Jun 2010 22:43:55 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Oops, there was a thinko in the patch, whereby wide strings would not be
entirely compared. Here’s an updated one:
diff --git a/libguile/srfi-13.c b/libguile/srfi-13.c
index c4e8571..f29ceaa 100644
--- a/libguile/srfi-13.c
+++ b/libguile/srfi-13.c
@@ -1,6 +1,6 @@
/* srfi-13.c --- SRFI-13 procedures for Guile
*
- * Copyright (C) 2001, 2004, 2005, 2006, 2008, 2009 Free Software Foundation,
Inc.
+ * Copyright (C) 2001, 2004, 2005, 2006, 2008, 2009, 2010 Free Software
Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -1168,6 +1168,26 @@ SCM_DEFINE (scm_string_eq, "string=", 2, 4, 0,
"value otherwise.")
#define FUNC_NAME s_scm_string_eq
{
+ if (SCM_LIKELY (scm_i_is_narrow_string (s1) == scm_i_is_narrow_string (s2)
+ && SCM_UNBNDP (start1) && SCM_UNBNDP (end1)
+ && SCM_UNBNDP (start2) && SCM_UNBNDP (end2)))
+ {
+ size_t len1, len2;
+
+ len1 = scm_i_string_length (s1);
+ len2 = scm_i_string_length (s2);
+
+ if (SCM_LIKELY (len1 == len2))
+ {
+ if (!scm_i_is_narrow_string (s1))
+ len1 *= 4;
+
+ return scm_from_bool (memcmp (scm_i_string_chars (s1),
+ scm_i_string_chars (s2),
+ len1) == 0);
+ }
+ }
+
return compare_strings (FUNC_NAME, 0,
s1, s2, start1, end1, start2, end2,
SCM_BOOL_F, SCM_BOOL_F, SCM_BOOL_F, SCM_BOOL_F,
SCM_BOOL_T);
Ludo’.