Commit dd429306 authored by Jon Coppeard's avatar Jon Coppeard
Browse files

Bug 1550009 - Make HashTable call templated alloc/free methods with the same type r=froydnj?

Differential Revision: https://phabricator.services.mozilla.com/D30371

--HG--
extra : moz-landing-system : lando
parent 17927a6b
Loading
Loading
Loading
Loading
+15 −8
Original line number Original line Diff line number Diff line
@@ -1610,14 +1610,15 @@ class HashTable : private AllocPolicy {


  enum FailureBehavior { DontReportFailure = false, ReportFailure = true };
  enum FailureBehavior { DontReportFailure = false, ReportFailure = true };


  static char* createTable(AllocPolicy& aAllocPolicy, uint32_t aCapacity,
                           FailureBehavior aReportFailure = ReportFailure) {
  // Fake a struct that we're going to alloc. See the comments in
  // Fake a struct that we're going to alloc. See the comments in
  // HashTableEntry about how the table is laid out, and why it's safe.
  // HashTableEntry about how the table is laid out, and why it's safe.
  struct FakeSlot {
  struct FakeSlot {
    unsigned char c[sizeof(HashNumber) + sizeof(typename Entry::NonConstT)];
    unsigned char c[sizeof(HashNumber) + sizeof(typename Entry::NonConstT)];
  };
  };


  static char* createTable(AllocPolicy& aAllocPolicy, uint32_t aCapacity,
                           FailureBehavior aReportFailure = ReportFailure) {

    FakeSlot* fake =
    FakeSlot* fake =
        aReportFailure
        aReportFailure
            ? aAllocPolicy.template pod_malloc<FakeSlot>(aCapacity)
            ? aAllocPolicy.template pod_malloc<FakeSlot>(aCapacity)
@@ -1639,7 +1640,13 @@ class HashTable : private AllocPolicy {
        slot.toEntry()->destroyStoredT();
        slot.toEntry()->destroyStoredT();
      }
      }
    });
    });
    aAllocPolicy.free_(aOldTable, aCapacity);
    freeTable(aAllocPolicy, aOldTable, aCapacity);
  }

  static void freeTable(AllocPolicy& aAllocPolicy, char* aOldTable,
                        uint32_t aCapacity) {
    FakeSlot* fake = reinterpret_cast<FakeSlot*>(aOldTable);
    aAllocPolicy.free_(fake, aCapacity);
  }
  }


 public:
 public:
@@ -1825,7 +1832,7 @@ class HashTable : private AllocPolicy {
    });
    });


    // All entries have been destroyed, no need to destroyTable.
    // All entries have been destroyed, no need to destroyTable.
    this->free_(oldTable, oldCapacity);
    freeTable(*this, oldTable, oldCapacity);
    return Rehashed;
    return Rehashed;
  }
  }


@@ -1965,7 +1972,7 @@ class HashTable : private AllocPolicy {
  void compact() {
  void compact() {
    if (empty()) {
    if (empty()) {
      // Free the entry storage.
      // Free the entry storage.
      this->free_(mTable, capacity());
      freeTable(*this, mTable, capacity());
      mGen++;
      mGen++;
      mHashShift = hashShift(0);  // gives minimum capacity on regrowth
      mHashShift = hashShift(0);  // gives minimum capacity on regrowth
      mTable = nullptr;
      mTable = nullptr;