36
36
import org .truffleruby .core .regexp .MatchDataNodesFactory .ValuesNodeFactory ;
37
37
import org .truffleruby .core .rope .Rope ;
38
38
import org .truffleruby .core .rope .RopeNodes ;
39
+ import org .truffleruby .core .rope .RopeOperations ;
39
40
import org .truffleruby .core .string .RubyString ;
40
41
import org .truffleruby .core .string .StringSupport ;
41
42
import org .truffleruby .core .string .StringUtils ;
@@ -314,18 +315,18 @@ protected Object getIndexSymbolKnownRegexp(RubyMatchData matchData, RubySymbol s
314
315
if (backRefs == 1 ) {
315
316
return executeGetIndex (matchData , backRefIndex , NotProvided .INSTANCE );
316
317
} else {
317
- final int i = getBackRef (matchData , cachedRegexp , nameEntry , lazyProfile , libInterop );
318
+ final int i = getBackRef (matchData , cachedRegexp , cachedSymbol . getRope () , lazyProfile , libInterop );
318
319
return executeGetIndex (matchData , i , NotProvided .INSTANCE );
319
320
}
320
321
}
321
322
322
323
@ Specialization
323
- protected Object getIndexSymbol (RubyMatchData matchData , RubySymbol index , NotProvided length ,
324
+ protected Object getIndexSymbol (RubyMatchData matchData , RubySymbol symbol , NotProvided length ,
324
325
@ Cached ConditionProfile lazyProfile ,
325
326
@ CachedLibrary (limit = "getInteropCacheLimit()" ) InteropLibrary libInterop ) {
326
327
return executeGetIndex (
327
328
matchData ,
328
- getBackRefFromSymbol (matchData , index , lazyProfile , libInterop ),
329
+ getBackRef (matchData , getRegexp ( matchData ), symbol . getRope () , lazyProfile , libInterop ),
329
330
NotProvided .INSTANCE );
330
331
}
331
332
@@ -336,7 +337,7 @@ protected Object getIndexString(RubyMatchData matchData, Object index, NotProvid
336
337
@ CachedLibrary (limit = "getInteropCacheLimit()" ) InteropLibrary libInterop ) {
337
338
return executeGetIndex (
338
339
matchData ,
339
- getBackRefFromRope (matchData , libIndex .getRope (index ), lazyProfile , libInterop ),
340
+ getBackRef (matchData , getRegexp ( matchData ) , libIndex .getRope (index ), lazyProfile , libInterop ),
340
341
NotProvided .INSTANCE );
341
342
}
342
343
@@ -396,46 +397,29 @@ protected RubyRegexp getRegexp(RubyMatchData matchData) {
396
397
return regexpNode .executeGetRegexp (matchData );
397
398
}
398
399
399
- private int getBackRefFromSymbol (RubyMatchData matchData , RubySymbol index , ConditionProfile lazyProfile ,
400
- InteropLibrary libInterop ) {
401
- return getBackRefFromRope (matchData , index .getRope (), lazyProfile , libInterop );
402
- }
403
-
404
- private int getBackRefFromRope (RubyMatchData matchData , Rope value , ConditionProfile lazyProfile ,
405
- InteropLibrary libInterop ) {
406
- if (lazyProfile .profile (matchData .tRegexResult != null )) {
407
- // force the calculation of lazy capture group results before invoking
408
- // nameToBackrefNumber
409
- forceLazyMatchData (matchData , libInterop );
410
- }
411
- return nameToBackrefNumber (matchData , getRegexp (matchData ), value .getBytes (), 0 , value .byteLength ());
412
- }
413
-
414
- private int getBackRef (RubyMatchData matchData , RubyRegexp regexp , NameEntry name , ConditionProfile lazyProfile ,
415
- InteropLibrary libInterop ) {
400
+ private int getBackRef (RubyMatchData matchData , RubyRegexp regexp , Rope name ,
401
+ ConditionProfile lazyProfile , InteropLibrary libInterop ) {
416
402
if (lazyProfile .profile (matchData .tRegexResult != null )) {
417
- // force the calculation of lazy capture group results before invoking
418
- // nameToBackrefNumber
403
+ // force the calculation of lazy capture group results before invoking nameToBackrefNumber()
419
404
forceLazyMatchData (matchData , libInterop );
420
405
}
421
- return nameToBackrefNumber (matchData , regexp , name . name , name . nameP , name . nameEnd );
406
+ return nameToBackrefNumber (matchData , regexp , name );
422
407
}
423
408
424
409
@ TruffleBoundary
425
- private int nameToBackrefNumber (RubyMatchData matchData , RubyRegexp regexp , byte [] name , int nameP ,
426
- int nameEnd ) {
410
+ private int nameToBackrefNumber (RubyMatchData matchData , RubyRegexp regexp , Rope name ) {
427
411
try {
428
412
return regexp .regex .nameToBackrefNumber (
429
- name ,
430
- nameP ,
431
- nameEnd ,
413
+ name . getBytes () ,
414
+ 0 ,
415
+ name . byteLength () ,
432
416
matchData .region );
433
417
} catch (ValueException e ) {
434
418
throw new RaiseException (
435
419
getContext (),
436
420
coreExceptions ().indexError (
437
421
StringUtils
438
- .format ("undefined group name reference: %s" , new String (name , nameP , nameEnd )),
422
+ .format ("undefined group name reference: %s" , RopeOperations . decodeRope (name )),
439
423
this ));
440
424
}
441
425
}
0 commit comments