Created
December 6, 2011 05:37
-
-
Save shirosaki/1436902 to your computer and use it in GitHub Desktop.
file_load_ok performance improvement for Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/file.c b/file.c | |
index e566ce3..516225d 100644 | |
--- a/file.c | |
+++ b/file.c | |
@@ -5060,7 +5060,33 @@ static int | |
file_load_ok(const char *path) | |
{ | |
int ret = 1; | |
- int fd = open(path, O_RDONLY); | |
+ int fd; | |
+#ifdef _WIN32 | |
+ static int use_attribute = -1; | |
+ if (use_attribute == -1) { | |
+ if (getenv("RUBY_USE_ATTRIBUTE") == NULL) { | |
+ use_attribute = 0; | |
+ } | |
+ else { | |
+ use_attribute = 1; | |
+ } | |
+ } | |
+ if (use_attribute) { | |
+ DWORD attr = GetFileAttributes(path); | |
+ if (attr == INVALID_FILE_ATTRIBUTES || | |
+ attr & FILE_ATTRIBUTE_DIRECTORY) { | |
+ return 0; | |
+ } | |
+ else { | |
+ return ret; | |
+ } | |
+ } | |
+ else { | |
+ fd = open(path, O_RDONLY); | |
+ } | |
+#else | |
+ fd = open(path, O_RDONLY); | |
+#endif | |
if (fd == -1) return 0; | |
rb_update_max_fd(fd); | |
#if !defined DOSISH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Benchmark result on Windows XP 32bit