File: fstr.rb

package info (click to toggle)
ruby-htree 0.8%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 5,928; makefile: 23
file content (32 lines) | stat: -rw-r--r-- 635 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'htree/modules'

module HTree
  # :stopdoc:
  def HTree.with_frozen_string_hash
    if Thread.current[:htree_frozen_string_hash]
      yield
    else
      begin
        Thread.current[:htree_frozen_string_hash] = {}
        yield
      ensure
        Thread.current[:htree_frozen_string_hash] = nil
      end
    end
  end

  def HTree.frozen_string(str)
    if h = Thread.current[:htree_frozen_string_hash]
      if s = h[str]
        s
      else
        str = str.dup.freeze unless str.frozen?
        h[str] = str
      end
    else
      str = str.dup.freeze unless str.frozen?
      str
    end
  end
  # :startdoc:
end