From: "bughit (bug hit) via ruby-core" Date: 2023-04-27T20:28:44+00:00 Subject: [ruby-core:113368] [Ruby master Feature#8707] Hash#reverse_each Issue #8707 has been updated by bughit (bug hit). > Do we really need it? What is use-cases? When you have an ordered collection it seems self evident that you may need to iterate in reverse. This would for example back a performant `last(n = 1)` method (#12165) Would you demand to know why one may want the last n elements of an array? These are both ordered collections, if `last(n = 1)` makes sense for one, it makes sense for the other. Why is this closed with a status of "Feedback"? ---------------------------------------- Feature #8707: Hash#reverse_each https://bugs.ruby-lang.org/issues/8707#change-102934 * Author: Glass_saga (Masaki Matsushita) * Status: Feedback * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- Currently, {}.reverse_each calls Enumerable#reverse_each. It will make array and its size can be large. I made Hash#reverse_each to avoid array creation and performance improvement. benchmark: require "benchmark" Size = 10000 HASH = Hash[*Array.new(Size) {|i| [i, true] }.flatten] Benchmark.bmbm do |x| x.report("Hash#reverse_each") do 300.times do HASH.reverse_each {|a, b|} end end end result: trunk(r42256): Rehearsal ----------------------------------------------------- Hash#reverse_each 1.210000 0.000000 1.210000 ( 1.207964) -------------------------------------------- total: 1.210000sec user system total real Hash#reverse_each 0.950000 0.000000 0.950000 ( 0.951069) proposal: Rehearsal ----------------------------------------------------- Hash#reverse_each 0.600000 0.000000 0.600000 ( 0.600242) -------------------------------------------- total: 0.600000sec user system total real Hash#reverse_each 0.450000 0.000000 0.450000 ( 0.459006) ---Files-------------------------------- patch.diff (7.55 KB) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/