Mailinglist Archive: yast-devel (81 mails)

< Previous Next >
[yast-devel] On the use of strings as hash keys
  • From: Klaus Kaempf <kkaempf@xxxxxxx>
  • Date: Thu, 22 Apr 2010 12:01:04 +0200
  • Message-id: <20100422100104.GA21327@xxxxxxxxxxxxx>
Hi,

when building hashes, watch for the type of hash keys.

Using strings (i.e. "key") affects performance since key operations involve
string
(character-by-character) compares.

Using symbols (i.e. :key) is faster and uses less resources. Symbols are
'interned', kept only once in memory, and compare operations are simple
integer compares.


Please keep this in mind when you see

{ "key" => ... }

and think about using

{ :key => ... }

instead.


Klaus

P.S.: Excessive hash usage should be replace by dedicated classes.

---
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG N├╝rnberg)

--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages