Skip to content

Commit

Permalink
small code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaong committed Feb 8, 2016
1 parent 64e10cc commit c1aea79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/immutable/vector.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module Immutable
# same position.
def initialize(elems : Array(T))
leaves = elems.size - (elems.size % Trie::BLOCK_SIZE)
@trie = Trie(T).from(elems[0...leaves], object_id)
@trie = Trie(T).from(elems[0...leaves], object_id).clear_owner!
@tail = elems[leaves..-1]
end

Expand Down Expand Up @@ -547,7 +547,9 @@ module Immutable
end

def initialize(elems : Array(T))
super(elems)
leaves = elems.size - (elems.size % Trie::BLOCK_SIZE)
@trie = Trie(T).from(elems[0...leaves], object_id)
@tail = elems[leaves..-1]
end

def persist!
Expand Down
10 changes: 5 additions & 5 deletions src/immutable/vector/trie.cr
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ module Immutable
self
end

def self.empty(from = nil : UInt64)
Trie.new([] of T, from)
def self.empty(owner = nil : UInt64)
Trie.new([] of T, owner)
end

def self.from(elems : Array(T))
Expand All @@ -203,10 +203,10 @@ module Immutable
trie
end

def self.from(elems : Array(T), from : UInt64)
trie = Trie(T).empty(from)
def self.from(elems : Array(T), owner : UInt64)
trie = Trie(T).empty(owner)
elems.each_slice(BLOCK_SIZE) do |leaf|
trie = trie.push_leaf!(leaf, from)
trie = trie.push_leaf!(leaf, owner)
end
trie.clear_owner!
end
Expand Down

0 comments on commit c1aea79

Please sign in to comment.