class StringPool
- StringPool
- Reference
- Object
Overview
A string pool is a collection of strings. It allows a runtime to save memory by preserving strings in a pool, allowing to reuse an instance of a common string instead of creating a new one.
NOTE To use StringPool
, you must explicitly import it with require "string_pool"
require "string_pool"
pool = StringPool.new
a = "foo" + "bar"
b = "foo" + "bar"
a.object_id # => 136294360
b.object_id # => 136294336
a = pool.get(a)
b = pool.get(b)
a.object_id # => 136294312
b.object_id # => 136294312
Included Modules
- Enumerable(String)
Direct Known Subclasses
Defined in:
string_store/string_pool_patch.crInstance Method Summary
- #[](hash : UInt64) : String
- #[](str : String) : UInt64
- #[]?(str : String) : UInt64 | Nil
- #[]?(hash : UInt64) : String | Nil
-
#each(&)
Must yield this collection's elements to the block.
- #get_id(str : Pointer(UInt8), len) : UInt64
- #get_id(str : String)
- #get_id(str : IO::Memory)
- #hash(str : String) : UInt64
- #hash(bytes : Bytes) : UInt64
Instance Method Detail
def each(&)
#
Description copied from module Enumerable(String)
Must yield this collection's elements to the block.