On Wed, 22 May 2024 14:32:23 GMT, Chen Liang <li...@openjdk.org> wrote:

>> Thanks.  Unfortunately the variable `cloneArray` is actually a method 
>> parameter, and most of the callers pass in `false` - so using this utility 
>> method to control cloning would actually introduce cloning in several places 
>> where it is explicitly avoided.  We may get a performance gain by modifying 
>> `Class.getInterfaces()` directly (the sole caller that passes `true`) then 
>> eliminating the parameter, then modifying each caller, etc. but that feels 
>> like a separate change inspired by this one.
>> 
>> Thoughts?
>
> Why can't you do something like this:
> 
> return cloneArray ? ReflectionFactory.copyClasses(interfaces) : interfaces;
> 
> 
> Alternatively, your proposal is a good one too; we can rename this 
> `getInterfaces(boolean)` to `getInterfacesShared()` (like 
> `getSharedEnumConstants()`) and move this copy operation to `getInterfaces()` 
> as you suggest.

I really see no reason to try and save on re-use of this one-line method for 
_everything_. In fact, I do not quite see a very compelling reason to even have 
the utility method. Sharing the code between `Method` and `Constructor` is 
clean enough and provides a good balance between reuse and cleanliness. 
Everything else can have the copy of the method definition, if needed.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19327#discussion_r1610112885

Reply via email to