public
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Search Repo:
Clean up the OrderedHash class used for css2sass a little.
nex3 (author)
Wed May 14 21:24:56 -0700 2008
commit  fc3d3d48df84276cd34849580f1ea711de8f44fd
tree    1ef18febe07bc94e5b9d12da310aa69ad6aecf5d
parent  7d617329318350707270d696282f2086c4d5792c
...
46
47
48
49
 
50
51
52
53
54
55
 
 
 
 
56
57
58
59
60
61
 
 
 
 
 
 
 
 
 
 
62
63
64
 
65
66
67
 
68
69
70
...
46
47
48
 
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
0
@@ -46,25 +46,40 @@ module Sass
0
   # It keeps the semantics and most of the efficiency of normal hashes
0
   # while also keeping track of the order in which elements were set.
0
   class OrderedHash
0
- Node = Struct.new('Node', :key, :value, :next)
0
+ Node = Struct.new(:key, :value, :next, :prev)
0
     include Enumerable
0
 
0
     def initialize
0
       @hash = {}
0
     end
0
 
0
+ def initialize_copy(other)
0
+ @hash = other.instance_variable_get('@hash').clone
0
+ end
0
+
0
     def [](key)
0
       @hash[key] && @hash[key].value
0
     end
0
 
0
     def []=(key, value)
0
- node = Node.new(key, value, nil)
0
+ node = Node.new(key, value)
0
+
0
+ if old = @hash[key]
0
+ if old.prev
0
+ old.prev.next = old.next
0
+ else # old is @first and @last
0
+ @first = @last = nil
0
+ end
0
+ end
0
+
0
       if @first.nil?
0
         @first = @last = node
0
       else
0
+ node.prev = @last
0
         @last.next = node
0
         @last = node
0
       end
0
+
0
       @hash[key] = node
0
       value
0
     end

Comments

    No one has commented yet.