Skip to content

Instantly share code, notes, and snippets.

@shirosaki
Created December 7, 2011 01:55
Show Gist options
  • Save shirosaki/1441067 to your computer and use it in GitHub Desktop.
Save shirosaki/1441067 to your computer and use it in GitHub Desktop.
diff --git a/file.c b/file.c
index e566ce3..24b25b8 100644
--- a/file.c
+++ b/file.c
@@ -5060,7 +5060,38 @@ 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) {
+ ret = 0;
+ }
+ else {
+ HANDLE h = CreateFile(path, GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h != INVALID_HANDLE_VALUE) {
+ CloseHandle(h);
+ }
+ else {
+ ret = 0;
+ }
+ }
+ return ret;
+ }
+#endif
+ fd = open(path, O_RDONLY);
if (fd == -1) return 0;
rb_update_max_fd(fd);
#if !defined DOSISH
@shirosaki
Copy link
Author

Benchmark on Windows XP
fenix enabled

# NOD32 realtime file system protection ON

[C:\devruby\measurements]set RUBY_USE_ATTRIBUTE=

[C:\devruby\measurements]rci bench core_require_empty
ruby 1.9.3p5 (2011-11-30) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   0.453000  12.406000  12.859000 ( 13.578125)
-------------------------------------------- total: 12.859000sec

                         user     system      total        real
core_require_empty   0.578000  12.172000  12.750000 ( 13.562500)

[C:\devruby\measurements]set RUBY_USE_ATTRIBUTE=1

[C:\devruby\measurements]rci bench core_require_empty
ruby 1.9.3p5 (2011-11-30) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   0.516000   3.641000   4.157000 (  4.859375)
--------------------------------------------- total: 4.157000sec

                         user     system      total        real
core_require_empty   0.484000   3.656000   4.140000 (  4.859375)


# NOD32 realtime file system protection OFF

[C:\devruby\measurements]set RUBY_USE_ATTRIBUTE=

[C:\devruby\measurements]rci bench core_require_empty
ruby 1.9.3p5 (2011-11-30) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   0.594000   3.344000   3.938000 (  4.125000)
--------------------------------------------- total: 3.938000sec

                         user     system      total        real
core_require_empty   0.547000   3.531000   4.078000 (  4.140625)

[C:\devruby\measurements]set RUBY_USE_ATTRIBUTE=1

[C:\devruby\measurements]rci bench core_require_empty
ruby 1.9.3p5 (2011-11-30) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   0.500000   1.938000   2.438000 (  2.640625)
--------------------------------------------- total: 2.438000sec

                         user     system      total        real
core_require_empty   0.406000   2.109000   2.515000 (  2.625000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment