2014-05-05 21:30:43 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
1999-12-22 04:56:45 +03:00
|
|
|
|
|
|
|
#ifndef nsDirectoryService_h___
|
|
|
|
#define nsDirectoryService_h___
|
|
|
|
|
2000-02-22 00:51:47 +03:00
|
|
|
#include "nsIDirectoryService.h"
|
2013-07-24 11:40:40 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
Bug 1411469 - Statically allocate static atoms. r=froydnj
Currently static atoms are stored on the heap, but their char buffers are
stored in read-only static memory.
This patch changes the representation of nsStaticAtom (thus making it a
non-trivial subclass of nsAtom). Instead of a pointer to the string, it now has
an mStringOffset field which is a 32-bit offset to the string. (This requires
placement of the string and the atom within the same object so that the offset
is known to be small. The docs and macros in nsStaticAtom.h handle that.)
Static and dynamic atoms now store their chars in different ways: nsStaticAtom
stores them inline, nsDynamicAtom has a pointer to separate storage. So
`mString` and GetStringBuffer() move from nsAtom to nsDynamicAtom.
The change to static atoms means they can be made constexpr and stored in
read-only memory instead of on the heap. On 64-bit this reduces the per-process
overhead by 16 bytes; on 32-bit the saving is 12 bytes. (Further reductions
will be possible in follow-up patches.)
The increased use of constexpr required multiple workarounds for MSVC.
- Multiple uses of MOZ_{PUSH,POP}_DISABLE_INTEGRAL_CONSTANT_OVERFLOW_WARNING to
disable warnings about (well-defined!) overflow of unsigned integer
arithmetic.
- The use of -Zc:externConstexpr on all files defining static atoms, to make
MSVC follow the C++ standard(!) and let constexpr variables have external
linkage.
- The use of -constexpr:steps300000 to increase the number of operations
allowed in a constexpr value, in order to handle gGkAtoms, which requires
hashing ~2,500 atom strings.
The patch also changes how HTML5 atoms are handled. They are now treated as
dynamic atoms, i.e. we have "dynamic normal" atoms and "dynamic HTML5 atoms",
and "dynamic atoms" covers both cases, and both are represented via
nsDynamicAtom. The main difference between the two kinds is that dynamic HTML5
atoms still aren't allowed to be used in various operations, most notably
AddRef()/Release(). All this also required moving nsDynamicAtom into the header
file.
There is a slight performance cost to all these changes: now that nsStaticAtom
and nsDynamicAtom store their chars in different ways, a conditional branch is
required in the following functions: Equals(), GetUTF16String(),
WeakAtom::as_slice().
Finally, in about:memory the "explicit/atoms/static/atom-objects" value is no
longer needed, because that memory is static instead of heap-allocated.
MozReview-Commit-ID: 4AxPv05ngZy
2018-03-08 04:59:11 +03:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2013-03-17 11:55:16 +04:00
|
|
|
#include "nsTArray.h"
|
2012-06-06 03:51:58 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-07-21 19:54:16 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2000-08-17 02:40:27 +04:00
|
|
|
|
2005-04-06 07:35:24 +04:00
|
|
|
#define NS_DIRECTORY_SERVICE_CID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2005-04-06 07:35:24 +04:00
|
|
|
0xf00152d0, 0xb40b, 0x11d3, { \
|
|
|
|
0x8c, 0x9c, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74 \
|
|
|
|
} \
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDirectoryService final : public nsIDirectoryService,
|
2014-05-15 00:15:46 +04:00
|
|
|
public nsIProperties,
|
|
|
|
public nsIDirectoryServiceProvider2 {
|
2014-05-05 21:30:43 +04:00
|
|
|
public:
|
2013-07-19 06:31:26 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
1999-12-22 04:56:45 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
NS_DECL_NSIPROPERTIES
|
1999-12-22 04:56:45 +03:00
|
|
|
|
2000-02-22 00:51:47 +03:00
|
|
|
NS_DECL_NSIDIRECTORYSERVICE
|
1999-12-22 04:56:45 +03:00
|
|
|
|
2000-02-22 00:51:47 +03:00
|
|
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2001-11-02 18:29:57 +03:00
|
|
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
|
1999-12-22 04:56:45 +03:00
|
|
|
|
2000-02-22 00:51:47 +03:00
|
|
|
nsDirectoryService();
|
2005-06-07 23:35:20 +04:00
|
|
|
|
2012-08-21 16:02:37 +04:00
|
|
|
static void RealInit();
|
2005-06-07 23:35:20 +04:00
|
|
|
void RegisterCategoryProviders();
|
1999-12-22 04:56:45 +03:00
|
|
|
|
2022-05-17 23:24:19 +03:00
|
|
|
static nsresult Create(REFNSIID aIID, void** aResult);
|
1999-12-22 04:56:45 +03:00
|
|
|
|
2016-07-21 19:54:16 +03:00
|
|
|
static mozilla::StaticRefPtr<nsDirectoryService> gService;
|
2004-01-15 09:14:18 +03:00
|
|
|
|
2019-12-02 16:56:14 +03:00
|
|
|
void SetCurrentProcessDirectory(nsIFile* aFile) { mXCurProcD = aFile; }
|
|
|
|
nsresult GetCurrentProcessDirectory(nsIFile**);
|
2019-09-04 15:04:52 +03:00
|
|
|
|
2005-06-07 23:35:20 +04:00
|
|
|
private:
|
2014-07-01 02:11:53 +04:00
|
|
|
~nsDirectoryService();
|
2019-09-04 15:04:52 +03:00
|
|
|
nsCOMPtr<nsIFile> mXCurProcD;
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
nsInterfaceHashtable<nsCStringHashKey, nsIFile> mHashtable;
|
2014-05-15 00:15:46 +04:00
|
|
|
nsTArray<nsCOMPtr<nsIDirectoryServiceProvider>> mProviders;
|
1999-12-22 04:56:45 +03:00
|
|
|
};
|
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
#endif
|