@@ -536,40 +536,50 @@ public static void checkArity(ThreadContext context, StaticScope scope, Object[]
536
536
}
537
537
}
538
538
539
- public static IRubyObject [] frobnicateKwargsArgument (ThreadContext context , IRubyObject [] args ,
540
- org .jruby .runtime .Signature signature ) {
541
- return frobnicateKwargsArgument (context , args , signature .required ());
542
- }
543
-
544
539
public static IRubyObject [] frobnicateKwargsArgument (ThreadContext context , IRubyObject [] args , int requiredArgsCount ) {
545
540
// No kwarg because required args slurp them up.
546
- return args .length <= requiredArgsCount ? args : frobnicateKwargsArgument (context , args );
547
- }
541
+ int length = args .length ;
542
+
543
+ if (length <= requiredArgsCount ) return args ;
544
+
545
+ final IRubyObject maybeKwargs = toHash (args [length - 1 ], context );
548
546
549
- private static IRubyObject [] frobnicateKwargsArgument (final ThreadContext context , IRubyObject [] args ) {
550
- final IRubyObject kwargs = toHash (args [args .length - 1 ], context );
551
- if (kwargs != null ) {
552
- if (kwargs .isNil ()) { // nil on to_hash is supposed to keep itself as real value so we need to make kwargs hash
547
+ if (maybeKwargs != null ) {
548
+ if (maybeKwargs .isNil ()) { // nil on to_hash is supposed to keep itself as real value so we need to make kwargs hash
553
549
return ArraySupport .newCopy (args , RubyHash .newSmallHash (context .runtime ));
554
550
}
555
551
556
- DivvyKeywordsVisitor visitor = new DivvyKeywordsVisitor ();
557
- // We know toHash makes null, nil, or Hash
558
- ((RubyHash ) kwargs ).visitAll (context , visitor , null );
552
+ RubyHash kwargs = (RubyHash ) maybeKwargs ;
559
553
560
- if (visitor .syms == null ) {
561
- // no symbols, use empty kwargs hash
562
- visitor .syms = RubyHash .newSmallHash (context .runtime );
554
+ if (kwargs .allSymbols ()) {
555
+ args [length - 1 ] = kwargs ;
556
+ } else {
557
+ args = homogenizeKwargs (context , args , kwargs );
563
558
}
559
+ }
564
560
565
- if (visitor .others != null ) { // rest args exists too expand args
566
- IRubyObject [] newArgs = new IRubyObject [args .length + 1 ];
567
- System .arraycopy (args , 0 , newArgs , 0 , args .length );
568
- args = newArgs ;
569
- args [args .length - 2 ] = visitor .others ; // opt args
570
- }
571
- args [args .length - 1 ] = visitor .syms ; // kwargs hash
561
+ return args ;
562
+ }
563
+
564
+ private static IRubyObject [] homogenizeKwargs (ThreadContext context , IRubyObject [] args , RubyHash kwargs ) {
565
+ DivvyKeywordsVisitor visitor = new DivvyKeywordsVisitor ();
566
+
567
+ // We know toHash makes null, nil, or Hash
568
+ kwargs .visitAll (context , visitor , null );
569
+
570
+ if (visitor .syms == null ) {
571
+ // no symbols, use empty kwargs hash
572
+ visitor .syms = RubyHash .newSmallHash (context .runtime );
572
573
}
574
+
575
+ if (visitor .others != null ) { // rest args exists too expand args
576
+ IRubyObject [] newArgs = new IRubyObject [args .length + 1 ];
577
+ System .arraycopy (args , 0 , newArgs , 0 , args .length );
578
+ args = newArgs ;
579
+ args [args .length - 2 ] = visitor .others ; // opt args
580
+ }
581
+ args [args .length - 1 ] = visitor .syms ; // kwargs hash
582
+
573
583
return args ;
574
584
}
575
585
@@ -1356,7 +1366,7 @@ public static DynamicMethod newInterpretedModuleBody(ThreadContext context, IRSc
1356
1366
@ JIT
1357
1367
public static DynamicMethod newCompiledModuleBody (ThreadContext context , MethodHandle handle , IRScope irModule , Object rubyContainer ) {
1358
1368
RubyModule newRubyModule = newRubyModuleFromIR (context , irModule , rubyContainer );
1359
- return new CompiledIRMethod (handle , irModule , Visibility .PUBLIC , newRubyModule , false );
1369
+ return new CompiledIRMethod (handle , irModule , Visibility .PUBLIC , newRubyModule );
1360
1370
}
1361
1371
1362
1372
private static RubyModule newRubyModuleFromIR (ThreadContext context , IRScope irModule , Object rubyContainer ) {
@@ -1380,7 +1390,7 @@ public static DynamicMethod newInterpretedClassBody(ThreadContext context, IRSco
1380
1390
public static DynamicMethod newCompiledClassBody (ThreadContext context , MethodHandle handle , IRScope irClassBody , Object container , Object superClass ) {
1381
1391
RubyModule newRubyClass = newRubyClassFromIR (context .runtime , irClassBody , superClass , container );
1382
1392
1383
- return new CompiledIRMethod (handle , irClassBody , Visibility .PUBLIC , newRubyClass , false );
1393
+ return new CompiledIRMethod (handle , irClassBody , Visibility .PUBLIC , newRubyClass );
1384
1394
}
1385
1395
1386
1396
public static RubyModule newRubyClassFromIR (Ruby runtime , IRScope irClassBody , Object superClass , Object container ) {
@@ -1431,7 +1441,7 @@ public static void defCompiledClassMethod(ThreadContext context, MethodHandle ha
1431
1441
RubyClass rubyClass = checkClassForDef (context , method , obj );
1432
1442
1433
1443
// FIXME: needs checkID and proper encoding to force hard symbol
1434
- rubyClass .addMethod (methodName .idString (), new CompiledIRMethod (handle , method , Visibility .PUBLIC , rubyClass , method . receivesKeywordArgs () ));
1444
+ rubyClass .addMethod (methodName .idString (), new CompiledIRMethod (handle , method , Visibility .PUBLIC , rubyClass ));
1435
1445
if (!rubyClass .isRefinement ()) {
1436
1446
// FIXME: needs checkID and proper encoding to force hard symbol
1437
1447
obj .callMethod (context , "singleton_method_added" , methodName );
@@ -1442,7 +1452,7 @@ public static void defCompiledClassMethod(ThreadContext context, MethodHandle ha
1442
1452
public static void defCompiledClassMethod (ThreadContext context , MethodHandle variable , MethodHandle specific , int specificArity , IRScope method , IRubyObject obj ) {
1443
1453
RubyClass rubyClass = checkClassForDef (context , method , obj );
1444
1454
1445
- rubyClass .addMethod (method .getId (), new CompiledIRMethod (variable , specific , specificArity , method , Visibility .PUBLIC , rubyClass , method . receivesKeywordArgs () ));
1455
+ rubyClass .addMethod (method .getId (), new CompiledIRMethod (variable , specific , specificArity , method , Visibility .PUBLIC , rubyClass ));
1446
1456
1447
1457
if (!rubyClass .isRefinement ()) obj .callMethod (context , "singleton_method_added" , method .getName ());
1448
1458
}
@@ -1485,7 +1495,7 @@ public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle
1485
1495
Visibility currVisibility = context .getCurrentVisibility ();
1486
1496
Visibility newVisibility = Helpers .performNormalMethodChecksAndDetermineVisibility (runtime , clazz , methodName , currVisibility );
1487
1497
1488
- DynamicMethod newMethod = new CompiledIRMethod (handle , method , newVisibility , clazz , method . receivesKeywordArgs () );
1498
+ DynamicMethod newMethod = new CompiledIRMethod (handle , method , newVisibility , clazz );
1489
1499
1490
1500
// FIXME: needs checkID and proper encoding to force hard symbol
1491
1501
Helpers .addInstanceMethod (clazz , methodName , newMethod , currVisibility , context , runtime );
@@ -1500,7 +1510,7 @@ public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle
1500
1510
Visibility currVisibility = context .getCurrentVisibility ();
1501
1511
Visibility newVisibility = Helpers .performNormalMethodChecksAndDetermineVisibility (runtime , clazz , methodName , currVisibility );
1502
1512
1503
- DynamicMethod newMethod = new CompiledIRMethod (variable , specific , specificArity , method , newVisibility , clazz , method . receivesKeywordArgs () );
1513
+ DynamicMethod newMethod = new CompiledIRMethod (variable , specific , specificArity , method , newVisibility , clazz );
1504
1514
1505
1515
// FIXME: needs checkID and proper encoding to force hard symbol
1506
1516
Helpers .addInstanceMethod (clazz , methodName , newMethod , currVisibility , context , runtime );
0 commit comments