16
16
import java .util .Collections ;
17
17
import java .util .List ;
18
18
import java .util .Map ;
19
- import java .util .concurrent .Callable ;
20
19
21
20
import org .hibernate .AssertionFailure ;
22
21
import org .hibernate .HibernateException ;
@@ -183,7 +182,7 @@ public ReflectionOptimizer getReflectionOptimizer(
183
182
.method ( setPropertyValuesMethodName )
184
183
.intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , getterNames , setters ) ) )
185
184
.method ( getPropertyNamesMethodName )
186
- .intercept ( MethodCall . call ( new CloningPropertyCall ( getterNames ) ) )
185
+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( getterNames ) ) )
187
186
);
188
187
189
188
try {
@@ -252,7 +251,7 @@ public ReflectionOptimizer getReflectionOptimizer(
252
251
.method ( setPropertyValuesMethodName )
253
252
.intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , propertyNames , setters ) ) )
254
253
.method ( getPropertyNamesMethodName )
255
- .intercept ( MethodCall . call ( new CloningPropertyCall ( propertyNames ) ) )
254
+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( propertyNames ) ) )
256
255
);
257
256
}
258
257
else {
@@ -265,7 +264,7 @@ public ReflectionOptimizer getReflectionOptimizer(
265
264
.method ( setPropertyValuesMethodName )
266
265
.intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , propertyNames , setters ) ) )
267
266
.method ( getPropertyNamesMethodName )
268
- .intercept ( MethodCall . call ( new CloningPropertyCall ( propertyNames ) ) )
267
+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( propertyNames ) ) )
269
268
);
270
269
}
271
270
@@ -1341,17 +1340,29 @@ private static Constructor<?> findConstructor(Class<?> clazz) {
1341
1340
}
1342
1341
}
1343
1342
1344
- public static class CloningPropertyCall implements Callable < String []> {
1343
+ public static class GetPropertyNames implements ByteCodeAppender {
1345
1344
1346
1345
private final String [] propertyNames ;
1347
1346
1348
- private CloningPropertyCall (String [] propertyNames ) {
1347
+ private GetPropertyNames (String [] propertyNames ) {
1349
1348
this .propertyNames = propertyNames ;
1350
1349
}
1351
1350
1352
1351
@ Override
1353
- public String [] call () {
1354
- return propertyNames .clone ();
1352
+ public Size apply (
1353
+ MethodVisitor methodVisitor ,
1354
+ Implementation .Context implementationContext ,
1355
+ MethodDescription instrumentedMethod ) {
1356
+ methodVisitor .visitLdcInsn ( propertyNames .length );
1357
+ methodVisitor .visitTypeInsn ( Opcodes .ANEWARRAY , Type .getInternalName ( String .class ) );
1358
+ for ( int i = 0 ; i < propertyNames .length ; i ++ ) {
1359
+ methodVisitor .visitInsn ( Opcodes .DUP );
1360
+ methodVisitor .visitLdcInsn ( i );
1361
+ methodVisitor .visitLdcInsn ( propertyNames [i ] );
1362
+ methodVisitor .visitInsn ( Opcodes .AASTORE );
1363
+ }
1364
+ methodVisitor .visitInsn ( Opcodes .ARETURN );
1365
+ return new Size ( 4 , instrumentedMethod .getStackSize () + 1 );
1355
1366
}
1356
1367
}
1357
1368
0 commit comments