Skip to content

Commit

Permalink
Fixes for each_byte
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 4, 2023
1 parent f58fb72 commit 0125c86
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyIOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ private RubyArray values(ThreadContext context, ByteBuffer buffer, DataType data

@JRubyMethod(name = "each_byte")
public IRubyObject each_byte(ThreadContext context, Block block) {
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each");
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each_byte");

ByteBuffer buffer = getBufferForReading(context);

Expand All @@ -1055,7 +1055,7 @@ public IRubyObject each_byte(ThreadContext context, Block block) {

@JRubyMethod(name = "each_byte")
public IRubyObject each_byte(ThreadContext context, IRubyObject _offset, Block block) {
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each", Helpers.arrayOf(_offset));
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each_byte", Helpers.arrayOf(_offset));

ByteBuffer buffer = getBufferForReading(context);
int offset = _offset.convertToInteger().getIntValue();
Expand All @@ -1065,7 +1065,7 @@ public IRubyObject each_byte(ThreadContext context, IRubyObject _offset, Block b

@JRubyMethod(name = "each_byte")
public IRubyObject each_byte(ThreadContext context, IRubyObject _offset, IRubyObject _count, Block block) {
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each", Helpers.arrayOf(_offset, _count));
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each_byte", Helpers.arrayOf(_offset, _count));

ByteBuffer buffer = getBufferForReading(context);
int offset = _offset.convertToInteger().getIntValue();
Expand All @@ -1078,7 +1078,7 @@ private IRubyObject eachByte(ThreadContext context, ByteBuffer buffer, int offse
Ruby runtime = context.runtime;

for (int i = 0 ; i < count; i++) {
IRubyObject value = wrap(runtime, readByte(context, buffer, offset));
IRubyObject value = wrap(runtime, readByte(context, buffer, offset + i));
block.yieldSpecific(context, value);
}

Expand Down

0 comments on commit 0125c86

Please sign in to comment.