Skip to content

Commit

Permalink
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ public class CoreString {
private final String literal;

@CompilationFinal private volatile Rope rope;
@CompilationFinal private volatile DynamicObject symbol;

public CoreString(RubyContext context, String literal) {
assert is7Bit(literal);
@@ -35,17 +36,23 @@ public CoreString(RubyContext context, String literal) {
public Rope getRope() {
if (rope == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
rope = createRope();

rope = context.getRopeTable().getRope(
literal.getBytes(StandardCharsets.US_ASCII),
ASCIIEncoding.INSTANCE,
CodeRange.CR_7BIT);
}

return rope;
}

private Rope createRope() {
// RopeTable.getRope is fully synchronized and returns the same object for equivalent parameters
return context.getRopeTable().getRope(
literal.getBytes(StandardCharsets.US_ASCII),
ASCIIEncoding.INSTANCE,
CodeRange.CR_7BIT);
public DynamicObject getSymbol() {
if (symbol == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
symbol = context.getSymbolTable().getSymbol(getRope());
}

return symbol;
}

public DynamicObject createInstance() {

4 comments on commit d1c95c2

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. Since you're expanding the use of the rope table, we should really fix the disappearing key problem. Just to recap, the keys in the rope table aren't retained anywhere else and since everything is a weak reference, values could be expunged from the table even if they're being held.

Sorry, something went wrong.

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please create an issue for that? We don't want it to get lost.

Sorry, something went wrong.

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

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

Recorded as #3740.

Please sign in to comment.