diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/xul/templates/nsResourceSet.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/xul/templates/nsResourceSet.cpp')
-rw-r--r-- | dom/xul/templates/nsResourceSet.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/dom/xul/templates/nsResourceSet.cpp b/dom/xul/templates/nsResourceSet.cpp new file mode 100644 index 000000000..64f4aad19 --- /dev/null +++ b/dom/xul/templates/nsResourceSet.cpp @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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 "nsResourceSet.h" + +nsResourceSet::nsResourceSet(const nsResourceSet& aResourceSet) + : mResources(nullptr), + mCount(0), + mCapacity(0) +{ + ConstIterator last = aResourceSet.Last(); + for (ConstIterator resource = aResourceSet.First(); resource != last; ++resource) + Add(*resource); +} + + +nsResourceSet& +nsResourceSet::operator=(const nsResourceSet& aResourceSet) +{ + Clear(); + ConstIterator last = aResourceSet.Last(); + for (ConstIterator resource = aResourceSet.First(); resource != last; ++resource) + Add(*resource); + return *this; +} + +nsResourceSet::~nsResourceSet() +{ + MOZ_COUNT_DTOR(nsResourceSet); + Clear(); + delete[] mResources; +} + +nsresult +nsResourceSet::Clear() +{ + while (--mCount >= 0) { + NS_RELEASE(mResources[mCount]); + } + mCount = 0; + return NS_OK; +} + +nsresult +nsResourceSet::Add(nsIRDFResource* aResource) +{ + NS_PRECONDITION(aResource != nullptr, "null ptr"); + if (! aResource) + return NS_ERROR_NULL_POINTER; + + if (Contains(aResource)) + return NS_OK; + + if (mCount >= mCapacity) { + int32_t capacity = mCapacity + 4; + nsIRDFResource** resources = new nsIRDFResource*[capacity]; + for (int32_t i = mCount - 1; i >= 0; --i) + resources[i] = mResources[i]; + + delete[] mResources; + + mResources = resources; + mCapacity = capacity; + } + + mResources[mCount++] = aResource; + NS_ADDREF(aResource); + return NS_OK; +} + +void +nsResourceSet::Remove(nsIRDFResource* aProperty) +{ + bool found = false; + + nsIRDFResource** res = mResources; + nsIRDFResource** limit = mResources + mCount; + while (res < limit) { + if (found) { + *(res - 1) = *res; + } + else if (*res == aProperty) { + NS_RELEASE(*res); + found = true; + } + ++res; + } + + if (found) + --mCount; +} + +bool +nsResourceSet::Contains(nsIRDFResource* aResource) const +{ + for (int32_t i = mCount - 1; i >= 0; --i) { + if (mResources[i] == aResource) + return true; + } + + return false; +} + |