From c1aea79fcd364794ce96f60a2d8c2c8108b91103 Mon Sep 17 00:00:00 2001 From: Luca Ongaro Date: Mon, 8 Feb 2016 19:28:02 +0100 Subject: [PATCH] small code improvements --- src/immutable/vector.cr | 6 ++++-- src/immutable/vector/trie.cr | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/immutable/vector.cr b/src/immutable/vector.cr index 9f7c86a..72ae3d8 100644 --- a/src/immutable/vector.cr +++ b/src/immutable/vector.cr @@ -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 @@ -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! diff --git a/src/immutable/vector/trie.cr b/src/immutable/vector/trie.cr index f2568f5..1f2fec0 100644 --- a/src/immutable/vector/trie.cr +++ b/src/immutable/vector/trie.cr @@ -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)) @@ -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