private void mergeStringIds() {
    new IdMerger<String>(idsDefsOut) {
      @Override
      TableOfContents.Section getSection(TableOfContents tableOfContents) {
        return tableOfContents.stringIds;
      }

      @Override
      String read(Dex.Section in, IndexMap indexMap, int index) {
        return in.readString();
      }

      @Override
      void updateIndex(int offset, IndexMap indexMap, int oldIndex, int newIndex) {
        indexMap.stringIds[oldIndex] = newIndex;
      }

      @Override
      void write(String value) {
        contentsOut.stringDatas.size++;
        idsDefsOut.writeInt(stringDataOut.getPosition());
        stringDataOut.writeStringData(value);
      }
    }.mergeSorted();
  }
minimum number of wasted bytes before it's worthwhile to compact the result
android/android_framework/dex-maker/src/main/java/com/android/dx/merge/DexMerger.java