dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: Re: [PATCH] pathname: reduce object allocation
Date: Wed, 16 Sep 2015 09:26:12 +0000	[thread overview]
Message-ID: <20150916-Feature-11375-interdiff@v1> (raw)
In-Reply-To: <20150916-Feature-11375-tweak@v1>

diff -u b/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb
--- b/ext/pathname/lib/pathname.rb
+++ b/ext/pathname/lib/pathname.rb
@@ -61,7 +61,9 @@
       File.dirname(prefix)
     elsif /#{SEPARATOR_PAT}/o =~ prefix
       prefix = File.dirname(prefix)
-      prefix = File.join(prefix, "".freeze) if File.basename(prefix + 'a'.freeze) != 'a'.freeze
+      if File.basename("#{prefix}a") != 'a'.freeze
+        prefix = File.join(prefix, "".freeze)
+      end
       prefix + relpath
     else
       prefix + relpath
@@ -98,8 +100,8 @@
     while r = chop_basename(pre)
       pre, base = r
       case base
-      when '.'.freeze
-      when '..'.freeze
+      when '.'
+      when '..'
         names.unshift base
       else
         if names[0] == '..'.freeze
@@ -130,10 +132,11 @@
 
   # add_trailing_separator(path) -> path
   def add_trailing_separator(path) # :nodoc:
-    if File.basename(path + 'a'.freeze) == 'a'.freeze
+    if File.basename("#{path}a") == 'a'.freeze
       path
     else
-      File.join(path, "".freeze) # xxx: Is File.join is appropriate to add separator?
+      # xxx: Is File.join is appropriate to add separator?
+      File.join(path, "".freeze)
     end
   end
   private :add_trailing_separator
@@ -369,7 +372,9 @@
       break unless r1 = chop_basename(prefix1)
       prefix1, basename1 = r1
       next if basename1 == '.'.freeze
-      if basename1 == '..'.freeze || basename_list2.empty? || basename_list2.first != '..'.freeze
+      if basename1 == '..'.freeze ||
+            basename_list2.empty? ||
+            basename_list2.first != '..'.freeze
         prefix1 = prefix1 + basename1
         break
       end
@@ -557,7 +562,9 @@
     return to_enum(__method__, ignore_error: ignore_error) unless block_given?
     require 'find'
     if @path == '.'.freeze
-      Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f.sub(%r{\A\./}, ''.freeze)) }
+      Find.find(@path, ignore_error: ignore_error) do |f|
+        yield self.class.new(f.sub(%r{\A\./}, ''.freeze))
+      end
     else
       Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f) }
     end

      reply	other threads:[~2015-09-16  9:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16  9:25 [PATCH] pathname: reduce object allocation Eric Wong
2015-09-16  9:26 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150916-Feature-11375-interdiff@v1 \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).