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: 2cb395e3fa9c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 392941f923e8
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 2, 2015

  1. Copy the full SHA
    a08fac9 View commit details
  2. Copy the full SHA
    b4a7cea View commit details
  3. Copy the full SHA
    2399ecd View commit details
  4. Copy the full SHA
    392941f View commit details
Binary file modified spec/truffle/tags/core/string/lstrip_tags.txt
Binary file not shown.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/rstrip_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/string/strip_tags.txt

This file was deleted.

167 changes: 141 additions & 26 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -1327,6 +1327,74 @@ public Object insert(VirtualFrame frame, RubyString string, int index, RubyStrin
}
}

@CoreMethod(names = "lstrip!", raiseIfFrozenSelf = true)
@ImportGuards(StringGuards.class)
public abstract static class LstripBangNode extends CoreMethodNode {

public LstripBangNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public LstripBangNode(LstripBangNode prev) {
super(prev);
}

@Specialization(guards = "isSingleByteOptimizable")
public Object lstripBangSingleByte(RubyString string) {
// Taken from org.jruby.RubyString#lstrip_bang19 and org.jruby.RubyString#singleByteLStrip.

if (string.getByteList().getRealSize() == 0) {
return nil();
}

final int s = string.getByteList().getBegin();
final int end = s + string.getByteList().getRealSize();
final byte[]bytes = string.getByteList().getUnsafeBytes();

int p = s;
while (p < end && ASCIIEncoding.INSTANCE.isSpace(bytes[p] & 0xff)) p++;
if (p > s) {
string.getByteList().view(p - s, end - p);
string.keepCodeRange();

return string;
}

return nil();
}

@Specialization(guards = "!isSingleByteOptimizable")
public Object lstripBang(RubyString string) {
// Taken from org.jruby.RubyString#lstrip_bang19 and org.jruby.RubyString#multiByteLStrip.

if (string.getByteList().getRealSize() == 0) {
return nil();
}

final Encoding enc = EncodingUtils.STR_ENC_GET(string);
final int s = string.getByteList().getBegin();
final int end = s + string.getByteList().getRealSize();
final byte[]bytes = string.getByteList().getUnsafeBytes();

int p = s;

while (p < end) {
int c = StringSupport.codePoint(getContext().getRuntime(), enc, bytes, p, end);
if (!ASCIIEncoding.INSTANCE.isSpace(c)) break;
p += StringSupport.codeLength(enc, c);
}

if (p > s) {
string.getByteList().view(p - s, end - p);
string.keepCodeRange();

return string;
}

return nil();
}
}

@CoreMethod(names = "match", required = 1, taintFromSelf = true)
public abstract static class MatchNode extends CoreMethodNode {

@@ -1498,6 +1566,79 @@ public Object rindex(VirtualFrame frame, RubyString string, RubyString subString
}
}

@CoreMethod(names = "rstrip!", raiseIfFrozenSelf = true)
@ImportGuards(StringGuards.class)
public abstract static class RstripBangNode extends CoreMethodNode {

public RstripBangNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public RstripBangNode(RstripBangNode prev) {
super(prev);
}

@Specialization(guards = "isSingleByteOptimizable")
public Object rstripBangSingleByte(RubyString string) {
// Taken from org.jruby.RubyString#rstrip_bang19 and org.jruby.RubyString#singleByteRStrip19.

if (string.getByteList().getRealSize() == 0) {
return nil();
}

final byte[] bytes = string.getByteList().getUnsafeBytes();
final int start = string.getByteList().getBegin();
final int end = start + string.getByteList().getRealSize();
int endp = end - 1;
while (endp >= start && (bytes[endp] == 0 ||
ASCIIEncoding.INSTANCE.isSpace(bytes[endp] & 0xff))) endp--;

if (endp < end - 1) {
string.getByteList().view(0, endp - start + 1);
string.keepCodeRange();

return string;
}

return nil();
}

@Specialization(guards = "!isSingleByteOptimizable")
public Object rstripBang(RubyString string) {
// Taken from org.jruby.RubyString#rstrip_bang19 and org.jruby.RubyString#multiByteRStrip19.

if (string.getByteList().getRealSize() == 0) {
return nil();
}

final Encoding enc = EncodingUtils.STR_ENC_GET(string);
final byte[] bytes = string.getByteList().getUnsafeBytes();
final int start = string.getByteList().getBegin();
final int end = start + string.getByteList().getRealSize();

int endp = end;
int prev;
while ((prev = prevCharHead(enc, bytes, start, endp, end)) != -1) {
int point = StringSupport.codePoint(getContext().getRuntime(), enc, bytes, prev, end);
if (point != 0 && !ASCIIEncoding.INSTANCE.isSpace(point)) break;
endp = prev;
}

if (endp < end) {
string.getByteList().view(0, endp - start);
string.keepCodeRange();

return string;
}
return nil();
}

@TruffleBoundary
private int prevCharHead(Encoding enc, byte[]bytes, int p, int s, int end) {
return enc.prevCharHead(bytes, p, s, end);
}
}

@CoreMethod(names = "swapcase", taintFromSelf = true)
public abstract static class SwapcaseNode extends CoreMethodNode {
public SwapcaseNode(RubyContext context, SourceSection sourceSection) {
@@ -1537,32 +1678,6 @@ public RubyString swapcase(RubyString string) {
}
}

@CoreMethod(names = "rstrip", taintFromSelf = true)
public abstract static class RStripNode extends CoreMethodNode {

public RStripNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public RStripNode(RStripNode prev) {
super(prev);
}

@Specialization
public RubyString rstrip(RubyString string) {
notDesignedForCompilation();

String str = string.toString();
int last = str.length()-1;
while (last >= 0 && " \r\n\t".indexOf(str.charAt(last)) != -1) {
last--;
}

return getContext().makeString(str.substring(0, last + 1));
}

}

@CoreMethod(names = "dump", taintFromSelf = true)
@ImportGuards(StringGuards.class)
public abstract static class DumpNode extends CoreMethodNode {