Skip to content

Commit b250992

Browse files
committed
Remove redundant access() calls for File.identical?
* The stat() calls done before already prove the files exist. * Also those calls returned an Integer, so the result was always true. * File.identical? returns true even if the files don't have read permission. * Remove now-unused access(), one might think it's faster for File.exist? but actually on Linux the truffleposix_stat_mode() approach seems faster (1.4Mi/s vs 1.0Mi/s).
1 parent 7733f5a commit b250992

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

src/main/ruby/truffleruby/core/file.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,7 @@ def self.identical?(orig, copy)
732732

733733
return false if Primitive.nil?(st_o) || Primitive.nil?(st_c)
734734

735-
st_o.dev == st_c.dev and st_o.ino == st_c.ino and st_o.ftype == st_c.ftype and
736-
POSIX.access(orig, Constants::R_OK) && Primitive.as_boolean(POSIX.access(copy, Constants::R_OK))
735+
st_o.dev == st_c.dev and st_o.ino == st_c.ino and st_o.ftype == st_c.ftype
737736
end
738737

739738
##

src/main/ruby/truffleruby/core/posix.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
171171
end
172172

173173
# Filesystem-related
174-
attach_function :access, [:string, :int], :int
175174
attach_function :chdir, [:string], :int
176175
attach_function :chmod, [:string, :mode_t], :int
177176
attach_function :chown, [:string, :uid_t, :gid_t], :int

0 commit comments

Comments
 (0)