From ba60b3f25fa528a7c5cdeb47db3d31ab5c8a8541 Mon Sep 17 00:00:00 2001 From: ocean Date: Mon, 16 Feb 2004 01:33:12 +0000 Subject: * dir.c (CompareImpl): File.fnmatch and Dir.glob get better performance in Win32. This is achived by calling downcase() for single-byte characters. CharLower() is only called for multi-byte characters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dir.c | 62 ++++++++++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 36 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 96fce7339e..19d37dd876 100644 --- a/dir.c +++ b/dir.c @@ -104,7 +104,6 @@ emx_mblen(p) #else /* multi byte environment */ # define Inc(p) ((p) = Next(p)) # define Compare(p1, p2) (CompareImpl(p1, p2, nocase)) -# ifndef _WIN32 static int CompareImpl(p1, p2, nocase) const char *p1; @@ -113,14 +112,39 @@ CompareImpl(p1, p2, nocase) { const int len1 = Next(p1) - p1; const int len2 = Next(p2) - p2; +#ifdef _WIN32 + char buf1[10], buf2[10]; /* large enough? */ +#endif if (len1 < 0 || len2 < 0) { - rb_fatal("No-win32 CompareImpl: negative len"); + rb_fatal("CompareImpl: negative len"); } if (len1 == 0) return len2; if (len2 == 0) return -len1; +#ifdef _WIN32 + if (nocase) { + if (len1 > 1) { + if (len1 >= sizeof(buf1)) { + rb_fatal("CompareImpl: too large len"); + } + memcpy(buf1, p1, len1); + buf1[len1] = '\0'; + CharLower(buf1); + p1 = buf1; /* trick */ + } + if (len2 > 1) { + if (len2 >= sizeof(buf2)) { + rb_fatal("CompareImpl: too large len"); + } + memcpy(buf2, p2, len2); + buf2[len2] = '\0'; + CharLower(buf2); + p2 = buf2; /* trick */ + } + } +#endif if (len1 == 1) if (len2 == 1) return compare(downcase(*p1), downcase(*p2)); @@ -138,40 +162,6 @@ CompareImpl(p1, p2, nocase) return ret ? ret : len1 - len2; } } -# else -static int -CompareImpl(p1, p2, nocase) - const char *p1; - const char *p2; - int nocase; -{ - int ret; - - const int len1 = Next(p1) - p1; - const int len2 = Next(p2) - p2; - - char buf1[10], buf2[10]; /* large enough? */ - - if (len1 < 0 || len2 < 0) { - rb_fatal("Win32 CompareImpl: negative len"); - } - - if (len1 >= sizeof(buf1) || len2 >= sizeof(buf2)) { - rb_fatal("Win32 CompareImpl: too large len"); - } - - memcpy(buf1, p1, len1); buf1[len1] = '\0'; - memcpy(buf2, p2, len2); buf2[len2] = '\0'; - - if (nocase) { - CharLower(buf1); - CharLower(buf2); - } - - ret = memcmp(buf1, buf2, len1 < len2 ? len1 : len2); - return ret ? ret : len1 - len2; -} -# endif #endif /* environment */ #if defined DOSISH -- cgit v1.2.3