Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Pig >> mail # user >> Question regarding DefaultTuple(size) implementation


Copy link to this message
-
Question regarding DefaultTuple(size) implementation
I rambled across this while reviewing one of Jon's patches. Here is the
code from DefaultTuple

/**
     * Construct a tuple with a known number of fields. Package level so
that callers cannot directly invoke it.
     * <br>Resulting tuple is filled pre-filled with null elements. Time
complexity: O(N), after allocation
     *
     * @param size
     *            Number of fields to allocate in the tuple.
     */
    DefaultTuple(int size) {
        mFields = new ArrayList<Object>(size);
        for (int i = 0; i < size; i++)
            mFields.add(null);
    }
Why are we walking through the list to add nulls? Wouldn't the initial
creation of ArrayList suffice?
mFields = new ArrayList<Object>(size) should be enough.

Thanks,
Prashant
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB