[前][次][番号順一覧][スレッド一覧]

ruby-changes:44817

From: normal <ko1@a...>
Date: Thu, 24 Nov 2016 08:57:35 +0900 (JST)
Subject: [ruby-changes:44817] normal:r56890 (trunk): resolv: use safe navigation operator to avoid extra hash lookups

normal	2016-11-24 08:57:30 +0900 (Thu, 24 Nov 2016)

  New Revision: 56890

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56890

  Log:
    resolv: use safe navigation operator to avoid extra hash lookups
    
    @addr2name is a private Hash and never changes its default_proc,
    so only pay the hash lookup cost once; we know missing entries
    in the hash will be nil.
    
    * lib/resolv.rb (each_name): use safe navigation operator

  Modified files:
    trunk/lib/resolv.rb
Index: lib/resolv.rb
===================================================================
--- lib/resolv.rb	(revision 56889)
+++ lib/resolv.rb	(revision 56890)
@@ -264,9 +264,7 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L264
 
     def each_name(address, &proc)
       lazy_initialize
-      if @addr2name.include?(address)
-        @addr2name[address].each(&proc)
-      end
+      @addr2name[address]&.each(&proc)
     end
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]