-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-19220] Replace boundary on StringByteIndexPrimitiveNode with fast…
…er specializations for boundary checks and single-byte-optimizable strings (#2380) PullRequest: truffleruby/2742
- Loading branch information
Showing
2 changed files
with
120 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2021 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 2.0, or | ||
* GNU General Public License version 2, or | ||
* GNU Lesser General Public License version 2.1. | ||
*/ | ||
|
||
package org.truffleruby.core.cast; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import org.jcodings.Encoding; | ||
import org.truffleruby.core.rope.Rope; | ||
import org.truffleruby.core.string.ImmutableRubyString; | ||
import org.truffleruby.core.string.RubyString; | ||
import org.truffleruby.language.RubyContextSourceNode; | ||
import org.truffleruby.language.RubyNode; | ||
|
||
@NodeChild(value = "child", type = RubyNode.class) | ||
public abstract class ToRopeNode extends RubyContextSourceNode { | ||
|
||
public abstract Rope executeToRope(Object object); | ||
|
||
public static ToRopeNode create() { | ||
return ToRopeNodeGen.create(null); | ||
} | ||
|
||
@Specialization | ||
protected Rope coerceRubyString(RubyString string) { | ||
return string.rope; | ||
} | ||
|
||
@Specialization | ||
protected Rope coerceImmutableRubyString(ImmutableRubyString string) { | ||
return string.rope; | ||
} | ||
|
||
@Fallback | ||
protected Encoding failure(Object value) { | ||
throw CompilerDirectives.shouldNotReachHere(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters