Skip to content

Commit 8c34d08

Browse files
committed
Skip transform_values when dealing with a Dry::Struct
This brings performance improvements of around 1.4-1.9x according to my benchmarks. `Hashify.[]` is already part of the implementation of `.to_h` for a `Dry::Struct`. Also makes it explocit that we are checking here for a `Dry::Struct`, not a `Struct` from stdlib.
1 parent 0951b92 commit 8c34d08

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/dry/struct/hashify.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ class Struct
55
# Helper for {Struct#to_hash} implementation
66
module Hashify
77
# Converts value to hash recursively
8-
# @param [#to_hash, #map, Object] value
8+
# @param [#to_hash, #to_ary, Object] value
99
# @return [Hash, Array]
1010
def self.[](value)
11-
if value.is_a?(Struct)
12-
value.to_h.transform_values { self[_1] }
11+
if value.is_a?(::Dry::Struct)
12+
value.to_h
1313
elsif value.respond_to?(:to_hash)
1414
value.to_hash.transform_values { self[_1] }
1515
elsif value.respond_to?(:to_ary)

0 commit comments

Comments
 (0)