2003-03-21 23:35:14 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2003-03-21 23:35:14 +03:00
|
|
|
|
|
|
|
#ifndef nsStaticAtom_h__
|
|
|
|
#define nsStaticAtom_h__
|
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
2010-03-08 18:44:59 +03:00
|
|
|
#include "nsStringBuffer.h"
|
|
|
|
#include "prlog.h"
|
2003-03-21 23:35:14 +03:00
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
typedef char16_t nsStaticAtomStringType;
|
|
|
|
|
2010-03-08 18:44:59 +03:00
|
|
|
#define NS_STATIC_ATOM(buffer_name, atom_ptr) { (nsStringBuffer*) &buffer_name, atom_ptr }
|
2013-09-18 07:43:21 +04:00
|
|
|
#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) };
|
2003-03-21 23:35:14 +03:00
|
|
|
|
2010-03-08 18:44:59 +03:00
|
|
|
/**
|
|
|
|
* Holds data used to initialize large number of atoms during startup. Use
|
|
|
|
* the above macros to initialize these structs. They should never be accessed
|
|
|
|
* directly other than from AtomTable.cpp
|
|
|
|
*/
|
2014-07-09 19:15:21 +04:00
|
|
|
struct nsStaticAtom
|
|
|
|
{
|
|
|
|
nsStringBuffer* mStringBuffer;
|
|
|
|
nsIAtom** mAtom;
|
2003-03-21 23:35:14 +03:00
|
|
|
};
|
|
|
|
|
2010-03-08 18:44:59 +03:00
|
|
|
/**
|
|
|
|
* This is a struct with the same binary layout as a nsStringBuffer.
|
|
|
|
*/
|
2014-07-09 19:15:21 +04:00
|
|
|
template<uint32_t size>
|
|
|
|
struct nsFakeStringBuffer
|
|
|
|
{
|
|
|
|
int32_t mRefCnt;
|
|
|
|
uint32_t mSize;
|
|
|
|
nsStaticAtomStringType mStringData[size];
|
2010-03-08 18:44:59 +03:00
|
|
|
};
|
2003-03-21 23:35:14 +03:00
|
|
|
|
2012-03-09 06:22:57 +04:00
|
|
|
// Register an array of static atoms with the atom table
|
2012-08-22 19:56:38 +04:00
|
|
|
template<uint32_t N>
|
2011-08-18 17:46:39 +04:00
|
|
|
nsresult
|
2014-07-09 19:15:21 +04:00
|
|
|
NS_RegisterStaticAtoms(const nsStaticAtom (&aAtoms)[N])
|
2012-03-09 06:22:57 +04:00
|
|
|
{
|
2014-07-09 19:15:21 +04:00
|
|
|
extern nsresult RegisterStaticAtoms(const nsStaticAtom*, uint32_t aAtomCount);
|
|
|
|
return RegisterStaticAtoms(aAtoms, N);
|
2012-03-09 06:22:57 +04:00
|
|
|
}
|
2003-03-21 23:35:14 +03:00
|
|
|
|
|
|
|
#endif
|