Skip to content

Commit

Permalink
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/bytes_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -609,11 +609,11 @@ public DynamicObject b(DynamicObject string) {

}

@CoreMethod(names = "bytes")
public abstract static class BytesNode extends CoreMethodArrayArgumentsNode {
@CoreMethod(names = "bytes", needsBlock = true)
public abstract static class BytesNode extends YieldingCoreMethodNode {

@Specialization
public DynamicObject bytes(DynamicObject string) {
public DynamicObject bytes(VirtualFrame frame, DynamicObject string, NotProvided block) {
final Rope rope = rope(string);
final byte[] bytes = rope.getBytes();

@@ -626,6 +626,18 @@ public DynamicObject bytes(DynamicObject string) {
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), store, store.length);
}

@Specialization
public DynamicObject bytes(VirtualFrame frame, DynamicObject string, DynamicObject block) {
Rope rope = rope(string);
byte[] bytes = rope.getBytes();

for (int i = 0; i < bytes.length; i++) {
yield(frame, block, bytes[i] & 0xff);
}

return string;
}

}

@CoreMethod(names = "bytesize")

1 comment on commit 55f6c7f

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This might be an interesting place to try out BytesVisitor too.

Please sign in to comment.