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: 4e42e84e4409
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 64157c655722
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Sep 28, 2015

  1. Copy the full SHA
    696babb View commit details
  2. Copy the full SHA
    a2c4477 View commit details
  3. Copy the full SHA
    64157c6 View commit details
Showing with 39 additions and 16 deletions.
  1. +39 −16 truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
55 changes: 39 additions & 16 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.EncodingOperations;
import org.jruby.truffle.runtime.core.StringCodeRangeableWrapper;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.*;
@@ -934,7 +935,7 @@ public DowncaseBangNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isSingleByteOptimizable(string)")
public DynamicObject downcaseSingleByte(DynamicObject string) {
final CodeRangeable codeRangeable = Layouts.STRING.getCodeRangeableWrapper(string);
final CodeRangeable codeRangeable = StringOperations.getCodeRangeable(string);
final ByteList bytes = codeRangeable.getByteList();

if (bytes.realSize() == 0) {
@@ -953,7 +954,7 @@ public DynamicObject downcaseSingleByte(DynamicObject string) {

@Specialization(guards = "!isSingleByteOptimizable(string)")
public DynamicObject downcase(DynamicObject string) {
final CodeRangeable codeRangeable = Layouts.STRING.getCodeRangeableWrapper(string);
final CodeRangeable codeRangeable = StringOperations.getCodeRangeable(string);
final ByteList bytes = codeRangeable.getByteList();
final Encoding encoding = bytes.getEncoding();

@@ -970,11 +971,16 @@ public DynamicObject downcase(DynamicObject string) {

codeRangeable.modifyAndKeepCodeRange();

final boolean modified = multiByteDowncase(encoding, bytes.unsafeBytes(), bytes.begin(), bytes.realSize());
if (modified) {
return string;
} else {
return nil();
try {
final boolean modified = multiByteDowncase(encoding, bytes.unsafeBytes(), bytes.begin(), bytes.realSize());
if (modified) {
return string;
} else {
return nil();
}
} catch (IllegalArgumentException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(e.getMessage(), this));
}
}

@@ -1419,10 +1425,22 @@ public OrdNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization
public int ord(DynamicObject string) {
return ((org.jruby.RubyFixnum) getContext().toJRubyString(string).ord(getContext().getRuntime().getCurrentContext())).getIntValue();
final StringCodeRangeableWrapper codeRangeable = StringOperations.getCodeRangeable(string);
final ByteList bytes = codeRangeable.getByteList();

try {
return codePoint(EncodingUtils.STR_ENC_GET(codeRangeable), bytes.getUnsafeBytes(), bytes.begin(), bytes.begin() + bytes.realSize());
} catch (IllegalArgumentException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(e.getMessage(), this));
}
}

@TruffleBoundary
private int codePoint(Encoding encoding, byte[] bytes, int p, int end) {
return StringSupport.codePoint(encoding, bytes, p, end);
}
}

@@ -2153,7 +2171,7 @@ public UpcaseBangNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isSingleByteOptimizable(string)")
public DynamicObject upcaseSingleByte(DynamicObject string) {
final CodeRangeable codeRangeable = Layouts.STRING.getCodeRangeableWrapper(string);
final CodeRangeable codeRangeable = StringOperations.getCodeRangeable(string);
final ByteList bytes = codeRangeable.getByteList();

if (bytes.realSize() == 0) {
@@ -2172,7 +2190,7 @@ public DynamicObject upcaseSingleByte(DynamicObject string) {

@Specialization(guards = "!isSingleByteOptimizable(string)")
public DynamicObject upcase(DynamicObject string) {
final CodeRangeable codeRangeable = Layouts.STRING.getCodeRangeableWrapper(string);
final CodeRangeable codeRangeable = StringOperations.getCodeRangeable(string);
final ByteList bytes = codeRangeable.getByteList();
final Encoding encoding = bytes.getEncoding();

@@ -2189,11 +2207,16 @@ public DynamicObject upcase(DynamicObject string) {

codeRangeable.modifyAndKeepCodeRange();

final boolean modified = multiByteUpcase(encoding, bytes.unsafeBytes(), bytes.begin(), bytes.realSize());
if (modified) {
return string;
} else {
return nil();
try {
final boolean modified = multiByteUpcase(encoding, bytes.unsafeBytes(), bytes.begin(), bytes.realSize());
if (modified) {
return string;
} else {
return nil();
}
} catch (IllegalArgumentException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(e.getMessage(), this));
}
}