Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove Array.attr_accessor :total

  • Loading branch information...
commit 2dd95c322feb610df489cc75e2ff650d5dd478f5 1 parent a9a40fc
Evan Phoenix evanphx authored
10 kernel/bootstrap/array.rb
View
@@ -1,18 +1,22 @@
# -*- encoding: us-ascii -*-
class Array
- attr_accessor :total
attr_accessor :tuple
attr_accessor :start
- alias_method :size, :total
- alias_method :length, :total
+ attr_reader_specific :total, :size
+ alias_method :length, :size
def self.allocate
Rubinius.primitive :array_allocate
raise PrimitiveFailure, "Array.allocate primitive failed"
end
+ def self.wrap(tuple, total)
+ Rubinius.primitive :array_wrap
+ raise PrimitiveFailure, "Array.wrap primitive failed"
+ end
+
def new_range(start, count)
Rubinius.primitive :array_new_range
raise PrimitiveFailure, "Array.new_range primitive failed"
6 kernel/common/array.rb
View
@@ -71,7 +71,7 @@ def replace(other)
other = Rubinius::Type.coerce_to other, Array, :to_ary
@tuple = other.tuple.dup
- @total = other.total
+ @total = other.size
@start = other.start
Rubinius::Type.infect(self, other)
@@ -220,7 +220,7 @@ def <=>(other)
return 0 if equal? other
return nil if other.nil?
- other_total = other.total
+ other_total = other.size
Thread.detect_recursion self, other do
i = 0
total = other_total < @total ? other_total : @total
@@ -1078,7 +1078,7 @@ def recursively_flatten(array, out, max_levels = -1)
max_levels -= 1
recursion = Thread.detect_recursion(array) do
i = array.start
- total = i + array.total
+ total = i + array.size
tuple = array.tuple
while i < total
10 kernel/common/array18.rb
View
@@ -193,9 +193,7 @@ def *(multiplier)
when 1
# Easy case
tuple = Rubinius::Tuple.pattern multiplier, at(0)
- out = self.class.allocate
- out.tuple = tuple
- out.total = multiplier
+ out = self.class.wrap tuple, multiplier
Rubinius::Type.infect(out, self) if multiplier != 0.0
return out
end
@@ -203,9 +201,7 @@ def *(multiplier)
new_total = multiplier * @total
new_tuple = Rubinius::Tuple.new(new_total)
- out = self.class.allocate
- out.tuple = new_tuple
- out.total = new_total
+ out = self.class.wrap new_tuple, new_total
Rubinius::Type.infect(out, self) if multiplier != 0.0
offset = 0
@@ -472,7 +468,7 @@ def uniq!
array = im.to_array
@tuple = array.tuple
@start = array.start
- @total = array.total
+ @total = array.size
self
end
10 kernel/common/array19.rb
View
@@ -168,9 +168,7 @@ def *(multiplier)
when 1
# Easy case
tuple = Rubinius::Tuple.pattern multiplier, at(0)
- out = self.class.allocate
- out.tuple = tuple
- out.total = multiplier
+ out = self.class.wrap tuple, multiplier
Rubinius::Type.infect(out, self)
return out
end
@@ -178,9 +176,7 @@ def *(multiplier)
new_total = multiplier * @total
new_tuple = Rubinius::Tuple.new(new_total)
- out = self.class.allocate
- out.tuple = new_tuple
- out.total = new_total
+ out = self.class.wrap new_tuple, new_total
Rubinius::Type.infect(out, self)
offset = 0
@@ -635,7 +631,7 @@ def uniq!(&block)
array = im.to_array
@tuple = array.tuple
@start = array.start
- @total = array.total
+ @total = array.size
self
end
5 kernel/common/tuple.rb
View
@@ -97,10 +97,7 @@ def ===(other)
end
def to_a
- ary = Array.allocate
- ary.tuple = dup
- ary.total = fields
- return ary
+ Array.wrap dup , fields
end
def shift
8 vm/builtin/array.cpp
View
@@ -53,6 +53,14 @@ namespace rubinius {
return ary;
}
+ Array* Array::wrap(STATE, Object* self, Tuple* tup, Fixnum* siz) {
+ Array* ary = allocate(state, self);
+ ary->tuple(state, tup);
+ ary->total(state, siz);
+
+ return ary;
+ }
+
Array* Array::new_range(STATE, Fixnum* start, Fixnum* count) {
Array* ary = state->new_object<Array>(class_object(state));
ary->total(state, count);
3  vm/builtin/array.hpp
View
@@ -38,6 +38,9 @@ namespace rubinius {
// Rubinius.primitive :array_allocate
static Array* allocate(STATE, Object* self);
+ // Rubinius.primitive :array_wrap
+ static Array* wrap(STATE, Object* self, Tuple* tup, Fixnum* size);
+
// Rubinius.primitive :array_new_range
Array* new_range(STATE, Fixnum* start, Fixnum* count);
Please sign in to comment.
Something went wrong with that request. Please try again.