You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by th...@apache.org on 2011/07/14 17:12:33 UTC

svn commit: r1146746 - in /pig/trunk: CHANGES.txt src/org/apache/pig/data/DefaultTuple.java

Author: thejas
Date: Thu Jul 14 15:12:33 2011
New Revision: 1146746

URL: http://svn.apache.org/viewvc?rev=1146746&view=rev
Log:
PIG-2001: DefaultTuple(List) constructor is inefficient, causes List.size() System.arraycopy() calls (though they are 0 byte copies), DefaultTuple(int) constructor is a bit misleading wrt time complexity (woody via thejas)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/data/DefaultTuple.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1146746&r1=1146745&r2=1146746&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Thu Jul 14 15:12:33 2011
@@ -24,6 +24,11 @@ INCOMPATIBLE CHANGES
 
 IMPROVEMENTS
 
+PIG-2001: DefaultTuple(List) constructor is inefficient, causes List.size()
+ System.arraycopy() calls (though they are 0 byte copies), 
+ DefaultTuple(int) constructor is a bit misleading wrt time 
+ complexity (woody via thejas)
+
 PIG-1916: Nested cross (zjshen via daijy)
 
 PIG-2128: Generating the jar file takes a lot of time and is unnecessary when running Pig local mode (julien)

Modified: pig/trunk/src/org/apache/pig/data/DefaultTuple.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/data/DefaultTuple.java?rev=1146746&r1=1146745&r2=1146746&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/data/DefaultTuple.java (original)
+++ pig/trunk/src/org/apache/pig/data/DefaultTuple.java Thu Jul 14 15:12:33 2011
@@ -54,6 +54,7 @@ public class DefaultTuple implements Tup
     /**
      * Default constructor. This constructor is public so that hadoop can call it directly. However, inside pig you
      * should never be calling this function. Use TupleFactory instead.
+     * <br>Time complexity: O(1), after allocation
      */
     public DefaultTuple() {
         mFields = new ArrayList<Object>();
@@ -61,6 +62,7 @@ public class DefaultTuple implements Tup
 
     /**
      * 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.
@@ -73,21 +75,17 @@ public class DefaultTuple implements Tup
 
     /**
      * Construct a tuple from an existing list of objects. Package level so that callers cannot directly invoke it.
-     * 
+     * <br>Time complexity: O(N) plus running time of input object iteration, after allocation
      * @param c
      *            List of objects to turn into a tuple.
      */
     DefaultTuple(List<Object> c) {
-        mFields = new ArrayList<Object>(c.size());
-
-        Iterator<Object> i = c.iterator();
-        int field;
-        for (field = 0; i.hasNext(); field++)
-            mFields.add(field, i.next());
+        mFields = new ArrayList<Object>(c);
     }
 
     /**
      * Construct a tuple from an existing list of objects. Package level so that callers cannot directly invoke it.
+     * <br>Time complexity: O(1)
      * 
      * @param c
      *            List of objects to turn into a tuple. This list will be kept as part of the tuple.