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