summaryrefslogtreecommitdiff
path: root/ext/pathname/lib
Commit message (Collapse)AuthorAgeFilesLines
* [ruby/pathname] Expose Pathname::VERSIONHiroshi SHIBATA2023-04-141-0/+2
| | | | https://github.com/ruby/pathname/commit/2b0b1a82ee
* [ruby/pathname] [Misc #19155] [DOC] Addion of absolute pathsNobuyoshi Nakada2022-12-031-0/+4
| | | | https://github.com/ruby/pathname/commit/3cb5ed2576
* [ruby/pathname] Fix `autoload` of `FileUtils`Nobuyoshi Nakada2022-07-271-2/+2
| | | | | | Should not be `Pathname::FileUtils`. https://github.com/ruby/pathname/commit/d1eb366e73
* Merge https://github.com/ruby/pathname/pull/8 for pathnameHiroshi SHIBATA2022-05-201-3/+4
|
* [Feature #16972] Add mode: option to Pathname#mkpathNobuyoshi Nakada2021-08-311-2/+2
|
* Faster Pathname FileUtils methodsschneems2021-08-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently when calling any of the "FileUtils" methods on pathname `require` is called every time even though that library might already be loaded. This is slow: We can speed it up by either checking first if the constant is already defined, or by using autoload. Using defined speeds up the action by about 300x and using autoload is about twice as fast as that (600x faster than current require method). I'm proposing we use autoload: ```ruby require 'benchmark/ips' Benchmark.ips do |x| autoload(:FileUtils, "fileutils") x.report("require") { require 'fileutils' } x.report("defined") { require 'fileutils' unless defined?(FileUtils) } x.report("autoload") { FileUtils } x.compare! end # Warming up -------------------------------------- # require 3.624k i/100ms # defined 1.465M i/100ms # autoload 2.320M i/100ms # Calculating ------------------------------------- # require 36.282k (± 2.4%) i/s - 184.824k in 5.097153s # defined 14.539M (± 2.0%) i/s - 73.260M in 5.041161s # autoload 23.100M (± 1.9%) i/s - 115.993M in 5.023271s # Comparison: # autoload: 23099779.2 i/s # defined: 14538544.9 i/s - 1.59x (± 0.00) slower # require: 36282.3 i/s - 636.67x (± 0.00) slower ``` Because this autoload is scoped to Pathname it will not change the behavior of existing programs that are not expecting FileUtils to be loaded yet: ``` ruby -rpathname -e "class Pathname; autoload(:FileUtils, 'fileutils'); end; puts FileUtils.exist?" Traceback (most recent call last): -e:1:in `<main>': uninitialized constant FileUtils (NameError) ```
* Optimize Pathname#relative? / absolute?Marc-Andre Lafortune2020-09-141-6/+9
|
* Document limitation of Pathname#relative_path_from [ci skip]Jeremy Evans2020-09-021-0/+3
| | | | | | | | | This method is explicitly documented to not access the filesystem, and the only way to get the correct behavior for a case where the filesystem's case sensitivity differs from the operating system default would be to access the filesystem. Fixes [Bug #15417]
* Remove unnecessary double bangs from Pathname#root?Masataka Pocke Kuwabara2019-12-171-1/+1
|
* Pathname#relative_path_from uses is_a?akr2018-12-181-6/+2
| | | | | | | I reconsidered because simpler code would have better maintainablity. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Pathname#relative_path_from compatible with mock.akr2018-12-161-2/+6
| | | | | | | [Fix GH-2049] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Pathname: Have #relative_path_from accept String argument.marcandre2018-11-131-0/+1
| | | | | | [Fix GH-1975] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Pathname: Simplified Pathname#mountpoint?nobu2018-08-101-2/+1
| | | | | | | | | Removed unnecessary comparison in mountpoint? [Fix GH-1927] From: John Whitson <john.whitson@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve Pathname performancewatson19782018-03-131-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If it will not use special variables (like $1, $&, $`...), it can improve the performance by using Regexp#match? instead of Regexp#=~. Because Regexp#=~ will generate the objects to special variables by pattern matching. This patch will replace Regexp#=~ without special variables to Regexp#match?. (Excludes https://github.com/ruby/ruby/blob/trunk/ext/pathname/lib/pathname.rb#L144-L153) [Fix GH-1836] [ruby-core:86093] [Bug #14599] ## Environment * OS : Ubuntu 17.10 * Compiler : gcc version 7.2.0 * CPU : Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz * Memory : 16 GB ## TL;DR   | Before | After | Speed up --------------------------- | ------ | ------ | -------- Pathname#absolute? | 142836 | 198487 | 39.0% Pathname#cleanpath | 60706 | 79415 | 30.8% Pathname#root? | 603806 | 759157 | 25.7% Pathname#absolute? | 142592 | 197859 | 38.8% Pathname#each_filename | 115600 | 152982 | 32.3% Pathname#ascend | 50494 | 63606 | 26.0% Pathname#+ | 100550 | 130372 | 29.7% Pathname#join | 46673 | 60994 | 30.7% Pathname#relative_path_from | 28362 | 37494 | 32.2% ## Before ``` Calculating ------------------------------------- Pathname#absolute? 142.836k (± 0.1%) i/s - 722.304k in 5.056884s Pathname#cleanpath 60.706k (± 0.1%) i/s - 306.764k in 5.053305s Pathname#root? 603.806k (± 0.3%) i/s - 3.062M in 5.071696s Pathname#absolute? 142.592k (± 0.1%) i/s - 720.846k in 5.055301s Pathname#each_filename 115.600k (± 0.1%) i/s - 586.818k in 5.076292s Pathname#ascend 50.494k (± 0.1%) i/s - 255.301k in 5.056049s Pathname#+ 100.550k (± 0.1%) i/s - 509.630k in 5.068433s Pathname#join 46.673k (± 0.1%) i/s - 236.433k in 5.065696s Pathname#relative_path_from 28.362k (± 0.0%) i/s - 143.728k in 5.067640s ``` ## After ``` Calculating ------------------------------------- Pathname#absolute? 198.487k (± 0.1%) i/s - 995.665k in 5.016272s Pathname#cleanpath 79.415k (± 0.1%) i/s - 404.406k in 5.092344s Pathname#root? 759.157k (± 0.0%) i/s - 3.800M in 5.005072s Pathname#absolute? 197.859k (± 0.1%) i/s - 995.720k in 5.032494s Pathname#each_filename 152.982k (± 0.1%) i/s - 775.555k in 5.069607s Pathname#ascend 63.606k (± 0.0%) i/s - 320.862k in 5.044560s Pathname#+ 130.372k (± 0.1%) i/s - 660.856k in 5.068991s Pathname#join 60.994k (± 0.1%) i/s - 305.068k in 5.001626s Pathname#relative_path_from 37.494k (± 0.4%) i/s - 189.124k in 5.044146s ``` ## Benchmark code ```ruby require 'pathname' require 'benchmark/ips' Benchmark.ips do |x| root = Pathname.new('/') path1 = Pathname.new('/path/to/some/file1.rb') path2 = Pathname.new('/path/to/some/file2.rb') x.report("Pathname#absolute?") do path1.absolute? end x.report("Pathname#cleanpath") do Pathname.new('/path/to/some/file.rb').cleanpath end x.report("Pathname#root?") do path1.root? end x.report("Pathname#absolute?") do path1.absolute? end x.report("Pathname#each_filename") do path1.each_filename { |file| } end x.report("Pathname#ascend") do path1.ascend { |path| } end x.report("Pathname#+") do path1 + path2 end x.report("Pathname#join") do path1.join("../file3.rb") end x.report("Pathname#relative_path_from") do path1.relative_path_from(root) end end ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* disable rdoc for internal constants [ci skip]nobu2017-08-031-0/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* pathname.rb: UNC root pathname needs a separatornobu2017-06-161-1/+1
| | | | | | | | | * ext/pathname/lib/pathname.rb (Pathname#plus): UNC root pathname needs a separator. File.basename returns "/" on UNC root, as well as sole drive letter, even if it does not end with a separator. [ruby-core:80900] [Bug #13515] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/open-uri.rb: Remove indicator for "frozen_string_literal: true".akr2015-11-101-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib/pp.rb: Ditto. * lib/prettyprint.rb: Ditto. * lib/resolv.rb: Ditto. * lib/securerandom.rb: Ditto. * lib/tmpdir.rb: Ditto. * lib/unicode_normalize/tables.rb: Ditto. * test/net/ftp/test_buffered_socket.rb: Ditto. * test/net/ftp/test_mlsx_entry.rb: Ditto. * test/open-uri/test_open-uri.rb: Ditto. * test/open-uri/test_ssl.rb: Ditto. * test/pathname/test_pathname.rb: Ditto. * test/test_pp.rb: Ditto. * test/test_prettyprint.rb: Ditto. * tool/transcode-tblgen.rb: Ditto. * ext/pathname/lib/pathname.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Put an line before "frozen_string_literal: true" for emacs.akr2015-10-051-0/+1
| | | | | | | https://bugs.ruby-lang.org/issues/8976#note-49 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb: freeze string literals forakr2015-10-041-0/+1
| | | | | | | | | reduced object allocation. patch by schneems. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb (descend): Blockless form supported.akr2015-06-141-0/+16
| | | | | | | | | (ascend): Ditto. [ruby-core:68820] [Feature #11052] Patch by Piotr Szotkowski. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb: Remove condition of RUBY_VERSION <= 1.9.hsbt2015-05-141-7/+2
| | | | | | [Feature #11082] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* pathname.rb: fix a Pathname#relative_path_from crash onnobu2014-09-151-1/+2
| | | | | | | | | | * ext/pathname/lib/pathname.rb (SAME_PATHS): Pathname#relative_path_from uses String#casecmp to compare strings on case-insensitive filesystem platforms (e.g., Windows). This can return nil for strings with different encodings, and the code previously assumed that it always returned a Fixnum. [Fix GH-713] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb (cleanpath_aggressive): make allakr2014-05-051-0/+2
| | | | | | | | | | | | separators File::SEPARATOR from File::ALT_SEPARATOR. Reported by Daniel Rikowski. Fixed by Nobuyoshi Nakada. [Bug #9618] * ext/pathname/lib/pathname.rb (cleanpath_conservative): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb (Pathname#/): Aliased to Pathname#+.akr2014-05-051-0/+5
| | | | | | | | Suggested by Alexey Muranov. [ruby-core:61432] [Feature #9625] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix error with empty args.kazu2014-04-021-0/+1
| | | | | | | | | | * ext/pathname/lib/pathname.rb (Pathname#join): Fix error with empty args. Reported by ko1 via IRC. * test/pathname/test_pathname.rb (TestPathname#test_join): Add the test for above case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* remove unnecessary unshiftkazu2014-03-251-2/+1
| | | | | | | * ext/pathname/lib/pathname.rb (Pathname#join): remove unnecessary unshift. * test/pathname/test_pathname.rb (TestPathname#test_join): add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb (Pathname#find): add "ignore_error"ktsj2014-03-041-4/+4
| | | | | | keyword argument defaulted to true as well as Find#find. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb: Hide private methods from RDoc.drbrain2012-12-111-9/+9
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb: Documentation for Pathname.zzak2012-09-121-48/+89
| | | | | | | | | * ext/pathname/pathname.c: ditto. [Bug #6947] [ruby-core:47354] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pathname.rb (Pathname#find): return an enumerator ifakr2011-11-191-0/+3
| | | | | | | | | | | | no block is given. * test/pathname/test_pathname.rb: add tests for above. [ruby-dev:44797] [Feature #5572] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb, ext/tk/lib/multi-tk.rb,ktsj2011-11-051-1/+1
| | | | | | | | | | | | | ext/tk/sample/demos-en/widget, lib/benchmark.rb, lib/irb/cmd/fork.rb, lib/mkmf.rb, lib/net/ftp.rb, lib/net/smtp.rb, lib/open3.rb, lib/pstore.rb, lib/rexml/element.rb, lib/rexml/light/node.rb, lib/rinda/tuplespace.rb, lib/rss/maker/base.rb, lib/rss/maker/entry.rb, lib/scanf.rb, lib/set.rb, lib/shell.rb, lib/shell/command-processor.rb, lib/shell/process-controller.rb, lib/shell/system-command.rb, lib/uri/common.rb: remove unused block arguments to avoid creating Proc objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb: Fix typos and grammar mistakes. Patchdrbrain2011-08-261-2/+2
| | | | | | | | | | | | | | | | by Luke Gruber. [#5203] * ext/pty/lib/expect.rb: ditto * lib/mathn.rb: ditto * lib/net/http.rb: ditto * lib/open-uri.rb: ditto * lib/ostruct.rb: ditto * lib/tempfile.rb: ditto * lib/thread.rb: ditto * lib/weakref.rb: ditto * sample/webrick/httpproxy.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_f_pathname): Pathname() translatedakr2010-09-211-10/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (Init_pathname): Pathname#=~ undefinitionakr2010-09-201-4/+0
| | | | | | | translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_unlink): Pathname#unlink andakr2010-09-181-13/+0
| | | | | | | Pathname#delete translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_each_entry): Pathname#each_entryakr2010-09-181-13/+0
| | | | | | | | translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_opendir): Pathname#opendir translatedakr2010-09-161-4/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_rmdir): Pathname#rmdir translatedakr2010-09-151-3/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_mkdir): Pathname#mkdir translatedakr2010-09-151-3/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_entries): Pathname#entries translatedakr2010-09-141-4/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_s_getwd): Pathname.getwd andakr2010-09-141-3/+0
| | | | | | | Pathname.pwd translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_s_glob): Pathname.glob translatedakr2010-09-131-9/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_zero_p): Pathname#zero? translatedakr2010-09-131-7/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_writable_real_p):akr2010-09-121-3/+0
| | | | | | | Pathname#writable_real? translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_world_writable_p):akr2010-09-121-3/+0
| | | | | | | Pathname#world_writable? translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_writable_p): Pathname#writable?akr2010-09-121-3/+0
| | | | | | | translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_symlink_p): Pathname#symlink?akr2010-09-101-3/+0
| | | | | | | translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_sticky_p): Pathname#sticky? translatedakr2010-09-101-3/+0
| | | | | | | from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_size_p): Pathname#size? translated fromakr2010-09-091-3/+0
| | | | | | | pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/pathname.c (path_size): Pathname#size translated fromakr2010-09-091-3/+0
| | | | | | | pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e