Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 96ee1d8017c9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a9f34c872ead
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 19, 2015

  1. Copy the full SHA
    5eccb58 View commit details
  2. Copy the full SHA
    a9f34c8 View commit details
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/

package org.jruby.truffle.nodes.core;

import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.StringSupport;

public class StringGuards {

public static boolean isSingleByteOptimizable(RubyString string) {
return StringSupport.isSingleByteOptimizable(string, string.getBytes().getEncoding());
}

}
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
@@ -1789,6 +1790,7 @@ public Object setByte(RubyString string, int index, Object value) {
}

@CoreMethod(names = {"size", "length"})
@ImportGuards(StringGuards.class)
public abstract static class SizeNode extends CoreMethodNode {

public SizeNode(RubyContext context, SourceSection sourceSection) {
@@ -1799,7 +1801,12 @@ public SizeNode(SizeNode prev) {
super(prev);
}

@Specialization
@Specialization(guards = "isSingleByteOptimizable")
public int sizeSingleByte(RubyString string) {
return string.getByteList().getRealSize();
}

@Specialization(guards = "!isSingleByteOptimizable")
public int size(RubyString string) {
return StringSupport.strLengthFromRubyString(string);
}
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
@@ -62,6 +63,7 @@
import org.jcodings.specific.ASCIIEncoding;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.TaintResultNode;
import org.jruby.truffle.nodes.core.StringGuards;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.StringNodesFactory;
import org.jruby.truffle.runtime.RubyContext;
@@ -574,6 +576,7 @@ public Object stringIndex(RubyString string, RubyString pattern, int start) {
}

@RubiniusPrimitive(name = "string_character_byte_index", needsSelf = false)
@ImportGuards(StringGuards.class)
public static abstract class CharacterByteIndexNode extends RubiniusPrimitiveNode {

public CharacterByteIndexNode(RubyContext context, SourceSection sourceSection) {
@@ -596,10 +599,6 @@ public int stringCharacterByteIndexMultiByteEncoding(RubyString string, int inde
return StringSupport.nth(bytes.getEncoding(), bytes.getUnsafeBytes(), bytes.getBegin(),
bytes.getBegin() + bytes.getRealSize(), start + index);
}

public static boolean isSingleByteOptimizable(RubyString string) {
return StringSupport.isSingleByteOptimizable(string, string.getBytes().getEncoding());
}
}

@RubiniusPrimitive(name = "string_byte_character_index", needsSelf = false)