gecko-dev/rdf/base/nsNameSpaceMap.h
Nicholas Nethercote dfd3b7e7aa Bug 1400459 (part 2) - Devirtualize nsIAtom. r=heycam.
This patch merges nsAtom into nsIAtom. For the moment, both names can be used
interchangeably due to a typedef. The patch also devirtualizes nsIAtom, by
making it not inherit from nsISupports, removing NS_DECL_NSIATOM, and dropping
the use of NS_IMETHOD_. It also removes nsIAtom's IIDs.

These changes trigger knock-on changes throughout the codebase, changing the
types of lots of things as follows.

- nsCOMPtr<nsIAtom> --> RefPtr<nsIAtom>

- nsCOMArray<nsIAtom> --> nsTArray<RefPtr<nsIAtom>>
  - Count() --> Length()
  - ObjectAt() --> ElementAt()
  - AppendObject() --> AppendElement()
  - RemoveObjectAt() --> RemoveElementAt()

- ns*Hashtable<nsISupportsHashKey, ...> -->
  ns*Hashtable<nsRefPtrHashKey<nsIAtom>, ...>

- nsInterfaceHashtable<T, nsIAtom> --> nsRefPtrHashtable<T, nsIAtom>
  - This requires adding a Get() method to nsRefPtrHashtable that it lacks but
    nsInterfaceHashtable has.

- nsCOMPtr<nsIMutableArray> --> nsTArray<RefPtr<nsIAtom>>
  - nsArrayBase::Create() --> nsTArray()
  - GetLength() --> Length()
  - do_QueryElementAt() --> operator[]

The patch also has some changes to Rust code that manipulates nsIAtom.

MozReview-Commit-ID: DykOl8aEnUJ

--HG--
extra : rebase_source : 254404e318e94b4c93ec8d4081ff0f0fda8aa7d1
2017-09-26 08:33:21 +10:00

99 lines
2.3 KiB
C++

/* -*- 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/. */
#ifndef nsNameSpaceMap_h__
#define nsNameSpaceMap_h__
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIAtom.h"
class nsNameSpaceMap
{
public:
class Entry {
public:
Entry(const nsACString& aURI, nsIAtom* aPrefix)
: mURI(aURI), mPrefix(aPrefix), mNext(nullptr) {
MOZ_COUNT_CTOR(nsNameSpaceMap::Entry); }
~Entry() { MOZ_COUNT_DTOR(nsNameSpaceMap::Entry); }
nsCString mURI;
RefPtr<nsIAtom> mPrefix;
Entry* mNext;
};
nsNameSpaceMap();
~nsNameSpaceMap();
nsresult
Put(const nsAString& aURI, nsIAtom* aPrefix);
nsresult
Put(const nsACString& aURI, nsIAtom* aPrefix);
class const_iterator {
protected:
friend class nsNameSpaceMap;
explicit const_iterator(const Entry* aCurrent)
: mCurrent(aCurrent) {}
const Entry* mCurrent;
public:
const_iterator()
: mCurrent(nullptr) {}
const_iterator(const const_iterator& iter)
: mCurrent(iter.mCurrent) {}
const_iterator&
operator=(const const_iterator& iter) {
mCurrent = iter.mCurrent;
return *this; }
const_iterator&
operator++() {
mCurrent = mCurrent->mNext;
return *this; }
const_iterator
operator++(int) {
const_iterator tmp(*this);
mCurrent = mCurrent->mNext;
return tmp; }
const Entry* operator->() const { return mCurrent; }
const Entry& operator*() const { return *mCurrent; }
bool
operator==(const const_iterator& iter) const {
return mCurrent == iter.mCurrent; }
bool
operator!=(const const_iterator& iter) const {
return ! iter.operator==(*this); }
};
const_iterator first() const {
return const_iterator(mEntries); }
const_iterator last() const {
return const_iterator(nullptr); }
const_iterator GetNameSpaceOf(const nsACString& aURI) const;
protected:
Entry* mEntries;
};
#endif // nsNameSpaceMap_h__