Cleanup BitMemoryReader/Writer api.

Test: test-art-host-gtest-stack_map_test
Test: test-art-host-gtest-bit_table_test
Change-Id: I15c624d2a70736aeb8422ce5babcef8e8fa82136
diff --git a/runtime/stack_map.h b/runtime/stack_map.h
index d6db05a..cde08f3 100644
--- a/runtime/stack_map.h
+++ b/runtime/stack_map.h
@@ -269,6 +269,26 @@
  */
 class CodeInfo {
  public:
+  class Deduper {
+   public:
+    explicit Deduper(std::vector<uint8_t>* output) : writer_(output) {
+      DCHECK_EQ(output->size(), 0u);
+    }
+
+    // Copy CodeInfo into output while de-duplicating the internal bit tables.
+    // It returns the byte offset of the copied CodeInfo within the output.
+    size_t Dedupe(const uint8_t* code_info);
+
+   private:
+    template<typename Accessor>
+    void DedupeTable(BitMemoryReader& reader);
+
+    BitMemoryWriter<std::vector<uint8_t>> writer_;
+
+    // Deduplicate at BitTable level. The value is bit offset within the output.
+    std::map<BitMemoryRegion, uint32_t, BitMemoryRegion::Less> dedupe_map_;
+  };
+
   enum DecodeFlags {
     Default = 0,
     // Limits the decoding only to the data needed by GC.
@@ -421,16 +441,6 @@
         DecodeVarintBits(reader));  // fp_spill_mask_.
   }
 
-  typedef std::map<BitMemoryRegion, uint32_t, BitMemoryRegion::Less> DedupeMap;
-
-  // Copy CodeInfo data while de-duplicating the internal bit tables.
-  // The 'out' vector must be reused between Dedupe calls (it does not have to be empty).
-  // The 'dedupe_map' stores the bit offsets of bit tables within the 'out' vector.
-  // It returns the byte offset of the copied CodeInfo within the 'out' vector.
-  static size_t Dedupe(std::vector<uint8_t>* out,
-                       const uint8_t* in,
-                       /*inout*/ DedupeMap* dedupe_map);
-
  private:
   // Returns lower bound (fist stack map which has pc greater or equal than the desired one).
   // It ignores catch stack maps at the end (it is the same as if they had maximum pc value).