DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (1a169f1e113d)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "DDLifetimes.h"

#include "DDLogUtils.h"

namespace mozilla {

DDLifetime* DDLifetimes::FindLifetime(const DDLogObject& aObject,
                                      const DDMessageIndex& aIndex) {
  LifetimesForObject* lifetimes = mLifetimes.Get(aObject);
  if (lifetimes) {
    for (DDLifetime& lifetime : *lifetimes) {
      if (lifetime.mObject == aObject && lifetime.IsAliveAt(aIndex)) {
        return &lifetime;
      }
    }
  }
  return nullptr;
}

const DDLifetime* DDLifetimes::FindLifetime(
    const DDLogObject& aObject, const DDMessageIndex& aIndex) const {
  const LifetimesForObject* lifetimes = mLifetimes.Get(aObject);
  if (lifetimes) {
    for (const DDLifetime& lifetime : *lifetimes) {
      if (lifetime.mObject == aObject && lifetime.IsAliveAt(aIndex)) {
        return &lifetime;
      }
    }
  }
  return nullptr;
}

DDLifetime& DDLifetimes::CreateLifetime(
    const DDLogObject& aObject, DDMessageIndex aIndex,
    const DDTimeStamp& aConstructionTimeStamp) {
  // Use negative tags for yet-unclassified messages.
  static int32_t sTag = 0;
  if (--sTag > 0) {
    sTag = -1;
  }
  LifetimesForObject* lifetimes = mLifetimes.LookupOrAdd(aObject, 1);
  DDLifetime& lifetime = *lifetimes->AppendElement(
      DDLifetime(aObject, aIndex, aConstructionTimeStamp, sTag));
  return lifetime;
}

void DDLifetimes::RemoveLifetime(const DDLifetime* aLifetime) {
  LifetimesForObject* lifetimes = mLifetimes.Get(aLifetime->mObject);
  MOZ_ASSERT(lifetimes);
  DDL_LOG(aLifetime->mMediaElement ? mozilla::LogLevel::Debug
                                   : mozilla::LogLevel::Warning,
          "Remove lifetime %s", aLifetime->Printf().get());
  // We should have been given a pointer inside this lifetimes array.
  auto arrayIndex = aLifetime - lifetimes->Elements();
  MOZ_ASSERT(static_cast<size_t>(arrayIndex) < lifetimes->Length());
  lifetimes->RemoveElementAt(arrayIndex);
}

void DDLifetimes::RemoveLifetimesFor(
    const dom::HTMLMediaElement* aMediaElement) {
  for (auto iter = mLifetimes.Iter(); !iter.Done(); iter.Next()) {
    iter.UserData()->RemoveElementsBy(
        [aMediaElement](const DDLifetime& lifetime) {
          return lifetime.mMediaElement == aMediaElement;
        });
  }
}

void DDLifetimes::Clear() { mLifetimes.Clear(); }

size_t DDLifetimes::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
  size_t size = mLifetimes.ShallowSizeOfExcludingThis(aMallocSizeOf);
  for (auto iter = mLifetimes.ConstIter(); !iter.Done(); iter.Next()) {
    size += iter.UserData()->ShallowSizeOfExcludingThis(aMallocSizeOf);
  }
  return size;
}

}  // namespace mozilla