[sip-comm-dev] Re: svn commit: r7622 - trunk/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java


#1

Matthieu, thank you for taking care of the details which've slipped by me!

I'd like to ask you about the advantages of the addAll change. Among
the obvious advantages are that the code is shorter (thus more
readable) and the functions used describe the intention more directly
(thus even more readable). Apart from any other advantages you've
seen, I'm also interested whether the addAll approach in this very
case is also more efficient in terms of garbage/memory and/or speed.

···

On Fri, Aug 20, 2010 at 12:27 PM, <kpouer@dev.java.net> wrote:

Used addAll() instead of a manual arrayCopy

Modified: trunk/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java
screenList = new ArrayList<ScreenDevice>(screens.length);
- for (ScreenDevice screen : screens)
- screenList.add(screen);
+ screenList.addAll(Arrays.asList(screens));

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#2

Hi,

···

2010/8/20 Lubomir Marinov <lubo@sip-communicator.org>:

On Fri, Aug 20, 2010 at 12:27 PM, <kpouer@dev.java.net> wrote:

Used addAll() instead of a manual arrayCopy

Modified: trunk/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java
screenList = new ArrayList<ScreenDevice>(screens.length);
- for (ScreenDevice screen : screens)
- screenList.add(screen);
+ screenList.addAll(Arrays.asList(screens));

Matthieu, thank you for taking care of the details which've slipped by me!

I'd like to ask you about the advantages of the addAll change. Among
the obvious advantages are that the code is shorter (thus more
readable) and the functions used describe the intention more directly
(thus even more readable). Apart from any other advantages you've
seen, I'm also interested whether the addAll approach in this very
case is also more efficient in terms of garbage/memory and/or speed.

The advantage of ArrayList.addAll(Collection) is that it use
internally System.arrayCopy() which is much faster than a for loop.
And the Arrays.asList() method is fast too because no array is copied,
the ArrayList is created using the given array instance

Matthieu

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net