Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10717 (new defect)

Opened 7 months ago

Last modified 7 months ago

[PATCH][TINY] stringify_keys cleanup and slight optimization to symbolize_keys!

Reported by: chuyeow Assigned to: core
Priority: low Milestone: 2.x
Component: ActiveSupport Version: edge
Severity: minor Keywords: tiny
Cc:

Description

Just minor "fixes", please read the diff attached since it's simple and clear.

Basically, remove the weird hack that doesn't seem to occur anymore in String#stringify_keys and also use assign the value of delete(key) right away.

Attachments

stringify_keys_patch.diff (0.6 kB) - added by chuyeow on 01/06/08 11:14:06.
minor_performance_improvements_to_keys_ext.diff (1.1 kB) - added by chuyeow on 01/06/08 14:13:07.
benchmark_sym.rb (0.7 kB) - added by chuyeow on 01/06/08 14:14:56.
script used for benchmarking alternative symbolize_keys! implementation

Change History

01/06/08 11:14:06 changed by chuyeow

  • attachment stringify_keys_patch.diff added.

01/06/08 14:13:07 changed by chuyeow

  • attachment minor_performance_improvements_to_keys_ext.diff added.

01/06/08 14:14:08 changed by chuyeow

  • summary changed from [PATCH][TINY] stringify_keys cleanup to [PATCH][TINY] stringify_keys cleanup and slight optimization to symbolize_keys!.

Adding a new patch that is a very slight optimization of #symbolize_keys!. Benchmarks on my machine are:

$ ruby benchmark_sym.rb 
Rehearsal ------------------------------------------------------------
existing symbolize_keys!   0.720000   0.010000   0.730000 (  0.736804)
new symbolize_keys!        0.510000   0.000000   0.510000 (  0.533631)
--------------------------------------------------- total: 1.240000sec

                               user     system      total        real
existing symbolize_keys!   0.720000   0.010000   0.730000 (  0.728628)
new symbolize_keys!        0.530000   0.000000   0.530000 (  0.534199)

(Benchmarking file is attached.)

01/06/08 14:14:56 changed by chuyeow

  • attachment benchmark_sym.rb added.

script used for benchmarking alternative symbolize_keys! implementation

01/06/08 18:16:36 changed by jamesh

Verified! Nice patch. +1

01/06/08 19:55:49 changed by bitsweat

btw, the symbolize_keys! speedup is essentially reverting [8333]

01/06/08 20:28:20 changed by bitsweat

(In [8576]) Simplify and speedup Hash#stringify_keys! References #10717 [Cheah Chu Yeow]