Browse Source

Fix for HADOOP-110. Reuse keys and values when mapping. Contributed by Owen O'Malley.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@390232 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 years ago
parent
commit
7d0429d4d2
1 changed files with 5 additions and 10 deletions
  1. 5 10
      src/java/org/apache/hadoop/mapred/MapRunner.java

+ 5 - 10
src/java/org/apache/hadoop/mapred/MapRunner.java

@@ -39,16 +39,11 @@ public class MapRunner implements MapRunnable {
                   Reporter reporter)
     throws IOException {
     try {
-      while (true) {
-        // allocate new key & value instances
-        WritableComparable key =
-          (WritableComparable)job.newInstance(inputKeyClass);
-        Writable value = (Writable)job.newInstance(inputValueClass);
-
-        // read next key & value
-        if (!input.next(key, value))
-          return;
-
+      // allocate key & value instances that are re-used for all entries
+      WritableComparable key =
+        (WritableComparable)job.newInstance(inputKeyClass);
+      Writable value = (Writable)job.newInstance(inputValueClass);
+      while (input.next(key, value)) {
         // map pair to output
         mapper.map(key, value, output, reporter);
       }