1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/ds/nsStaticAtom.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsStaticAtom_h__ 1.10 +#define nsStaticAtom_h__ 1.11 + 1.12 +#include "nsIAtom.h" 1.13 +#include "nsStringBuffer.h" 1.14 +#include "prlog.h" 1.15 + 1.16 +typedef char16_t nsStaticAtomStringType; 1.17 + 1.18 +#define NS_STATIC_ATOM(buffer_name, atom_ptr) { (nsStringBuffer*) &buffer_name, atom_ptr } 1.19 +#define NS_STATIC_ATOM_BUFFER(buffer_name, str_data) static nsFakeStringBuffer< sizeof(str_data) > buffer_name = { 1, sizeof(str_data) * sizeof(nsStaticAtomStringType), MOZ_UTF16(str_data) }; 1.20 + 1.21 +/** 1.22 + * Holds data used to initialize large number of atoms during startup. Use 1.23 + * the above macros to initialize these structs. They should never be accessed 1.24 + * directly other than from AtomTable.cpp 1.25 + */ 1.26 +struct nsStaticAtom { 1.27 + nsStringBuffer* mStringBuffer; 1.28 + nsIAtom ** mAtom; 1.29 +}; 1.30 + 1.31 +/** 1.32 + * This is a struct with the same binary layout as a nsStringBuffer. 1.33 + */ 1.34 +template <uint32_t size> 1.35 +struct nsFakeStringBuffer { 1.36 + int32_t mRefCnt; 1.37 + uint32_t mSize; 1.38 + nsStaticAtomStringType mStringData[size]; 1.39 +}; 1.40 + 1.41 +// Register an array of static atoms with the atom table 1.42 +template<uint32_t N> 1.43 +nsresult 1.44 +NS_RegisterStaticAtoms(const nsStaticAtom (&atoms)[N]) 1.45 +{ 1.46 + extern nsresult RegisterStaticAtoms(const nsStaticAtom*, uint32_t aAtomCount); 1.47 + return RegisterStaticAtoms(atoms, N); 1.48 +} 1.49 + 1.50 +#endif