private final RubyArray makeShared(int beg, int len, RubyArray sharedArray) { unpack(); isShared = true; sharedArray.values = values; sharedArray.isShared = true; sharedArray.begin = beg; sharedArray.realLength = len; return sharedArray; }
private final RubyArray makeShared(int beg, int len, RubyArray sharedArray) { unpack(); isShared = true; sharedArray.values = values; sharedArray.isShared = true; sharedArray.begin = beg; sharedArray.realLength = len; return sharedArray; }
public IRubyObject[] toJavaArrayUnsafe() { unpack(); return !isShared ? values : toJavaArray(); }
public IRubyObject[] toJavaArrayMaybeUnsafe() { unpack(); return (!isShared && begin == 0 && values.length == realLength) ? values : toJavaArray(); }
public IRubyObject[] toJavaArrayUnsafe() { unpack(); return !isShared ? values : toJavaArray(); }
public IRubyObject[] toJavaArrayMaybeUnsafe() { unpack(); return (!isShared && begin == 0 && values.length == realLength) ? values : toJavaArray(); }
/** * Increases the capacity of this <tt>Array</tt>, if necessary. * @param minCapacity the desired minimum capacity of the internal array */ @Deprecated public void ensureCapacity(int minCapacity) { unpack(); if ( isShared || (values.length - begin) < minCapacity ) { final int len = this.realLength; int newCapacity = minCapacity > len ? minCapacity : len; IRubyObject[] values = new IRubyObject[newCapacity]; ArraySupport.copy(this.values, begin, values, 0, len); this.values = values; this.begin = 0; } }
/** rb_ary_make_shared * */ private RubyArray makeShared() { // TODO: (CON) Some calls to makeShared could create packed array almost as efficiently unpack(); return makeShared(begin, realLength, getMetaClass()); }
/** rb_ary_make_shared * */ private RubyArray makeShared() { // TODO: (CON) Some calls to makeShared could create packed array almost as efficiently unpack(); return makeShared(begin, realLength, getMetaClass()); }
/** rb_ary_shift * */ @JRubyMethod(name = "shift") public IRubyObject shift(ThreadContext context) { unpack(); modifyCheck(); if (realLength == 0) return context.nil; final IRubyObject obj = safeArrayRefCondSet(context.runtime, values, begin, !isShared, context.nil); begin++; realLength--; return obj; }
/** rb_ary_shift * */ @JRubyMethod(name = "shift") public IRubyObject shift(ThreadContext context) { unpack(); modifyCheck(); if (realLength == 0) return context.nil; final IRubyObject obj = safeArrayRefCondSet(context.runtime, values, begin, !isShared, context.nil); begin++; realLength--; return obj; }
@JRubyMethod(name = "shift") public IRubyObject shift(ThreadContext context, IRubyObject num) { unpack(); modify(); RubyArray result = makeSharedFirst(context, num, false, context.runtime.getArray()); int n = result.realLength; begin += n; realLength -= n; return result; }
@JRubyMethod public IRubyObject pop(ThreadContext context, IRubyObject num) { unpack(); modifyCheck(); RubyArray result = makeSharedFirst(context, num, true, context.runtime.getArray()); realLength -= result.realLength; return result; }
private void realloc(int newLength, int valuesLength) { unpack(); IRubyObject[] reallocated = new IRubyObject[newLength]; if (newLength > valuesLength) { Helpers.fillNil(reallocated, valuesLength, newLength, getRuntime()); safeArrayCopy(values, begin, reallocated, 0, valuesLength); // elements and trailing nils } else { safeArrayCopy(values, begin, reallocated, 0, newLength); // ??? } begin = 0; values = reallocated; }
@JRubyMethod(name = "shift") public IRubyObject shift(ThreadContext context, IRubyObject num) { unpack(); modify(); RubyArray result = makeSharedFirst(context, num, false, context.runtime.getArray()); int n = result.realLength; begin += n; realLength -= n; return result; }
private void realloc(int newLength, int valuesLength) { unpack(); IRubyObject[] reallocated = new IRubyObject[newLength]; if (newLength > valuesLength) { Helpers.fillNil(reallocated, valuesLength, newLength, getRuntime()); safeArrayCopy(values, begin, reallocated, 0, valuesLength); // elements and trailing nils } else { safeArrayCopy(values, begin, reallocated, 0, newLength); // ??? } begin = 0; values = reallocated; }
@JRubyMethod public IRubyObject pop(ThreadContext context, IRubyObject num) { unpack(); modifyCheck(); RubyArray result = makeSharedFirst(context, num, true, context.runtime.getArray()); realLength -= result.realLength; return result; }
/** rb_ary_pop * */ @JRubyMethod public IRubyObject pop(ThreadContext context) { unpack(); modifyCheck(); if (realLength == 0) return context.nil; if (isShared) { return safeArrayRef(context.runtime, values, begin + --realLength); } else { int index = begin + --realLength; return safeArrayRefSet(context.runtime, values, index, context.nil); } }
/** rb_ary_initialize * */ @JRubyMethod(visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, Block block) { modifyCheck(); unpack(); Ruby runtime = context.runtime; realLength = 0; if (block.isGiven() && runtime.isVerbose()) { runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); } return this; }
@JRubyMethod(name = "insert", required = 1, rest = true) public IRubyObject insert(IRubyObject[] args) { modifyCheck(); if (args.length == 1) return this; unpack(); long pos = RubyNumeric.num2long(args[0]); if (pos == -1) pos = realLength; if (pos < 0) pos++; final Ruby runtime = getRuntime(); RubyArray inserted = new RubyArray(runtime, false); inserted.values = args; inserted.begin = 1; inserted.realLength = args.length - 1; splice(runtime, (int) pos, 0, inserted, inserted.realLength); // rb_ary_new4 return this; }