[ 
https://issues.apache.org/jira/browse/HDFS-12653?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16204273#comment-16204273
 ] 

Manoj Govindassamy commented on HDFS-12653:
-------------------------------------------

[~daryn],
  Currently ReadOnlyList is predominantly used by the Directory and Snapshot 
subsystems for storing their children inodes / snapshots  in a _sorted_ order. 
I see it as a SortedList and many a times the users of this list make use of 
the sorted nature of the elements for searching - 
{{ReadOnlyList#Util#binarySearch(ReadOnlyList<E>, K key)}}. On top of this 
sorted benefits, {{ReadOnlyList#Util#asList()}} gives a {{List}} where  
{{toArray()}} differs significantly from the Collections toArray -- the 
returned array is more of a _view_ of the backing read only list, without 
copying any elements. 
 
  I believe we can make use of ReadOnlyList for enhancing the performance of 
{{INodeAttributesProvider#getAttributes()}} by converting byte[][] 
bPathComponents to ReadOnlyList<String> sPathComponents only one time and 
getting the _view_ of the string path components using toArray() or 
subArray(start, end). Collections doesn't have subArray() concept, theres only 
subList(). 


> Implement toArray() and subArray() for ReadOnlyList
> ---------------------------------------------------
>
>                 Key: HDFS-12653
>                 URL: https://issues.apache.org/jira/browse/HDFS-12653
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>            Reporter: Manoj Govindassamy
>            Assignee: Manoj Govindassamy
>
> {{ReadOnlyList}} today gives an unmodifiable view of the backing List. This 
> list supports following Util methods for easy construction of read only views 
> of any given list. 
> {noformat}
> public static <E> ReadOnlyList<E> asReadOnlyList(final List<E> list) 
> public static <E> List<E> asList(final ReadOnlyList<E> list)
> {noformat}
> {{asList}} above additionally overrides {{Object[] toArray()}} of the 
> {{java.util.List}} interface. Unlike the {{java.util.List}}, the above one 
> returns an array of Objects referring to the backing list and avoid any 
> copying of objects. Given that we have many usages of read only lists,
> 1. Lets have a light-weight / shared-view {{toArray()}} implementation for 
> {{ReadOnlyList}} as well. 
> 2. Additionally, similar to {{java.util.List#subList(fromIndex, toIndex)}}, 
> lets have {{ReadOnlyList#subArray(fromIndex, toIndex)}}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to