Commit Graph

315 Commits

Author SHA1 Message Date
Tim Huang
2e3e3f27ec Bug 1417741 - Add support of Atmoic<> for Preferences::Add*VarCache(). r=baku,njn
MozReview-Commit-ID: 9aeLvgWdZxy
2017-11-16 11:02:50 +08:00
Nicholas Nethercote
06a08f05d5 Bug 1418467 - Privatize PrefHashEntry::m{Default,User}Value. r=glandium
MozReview-Commit-ID: 9Fzaf4ifF0N
2017-11-18 07:40:01 +11:00
Nicholas Nethercote
bf23eec9a4 Bug 1418467 - Add PrefHashEntry::SetValue(). r=glandium
It's a horrible method, but the horribleness was pre-existing. I hope to make
it nicer in a follow-up bug.

MozReview-Commit-ID: 3tMTEeBNVax
2017-11-18 07:38:24 +11:00
Nicholas Nethercote
5f752d4481 Bug 1418467 - Partly move value getting into PrefHashEntry. r=glandium
MozReview-Commit-ID: 4ouh3XFxPZr
2017-11-18 07:28:29 +11:00
Nicholas Nethercote
6db3290fe5 Bug 1418467 - Add PrefHashEntry::UserValueToStringForSaving(). r=glandium
This moves part of pref_savePrefs() into PrefHashEntry.

This requires moving StrEscape() higher up to avoid a forward declaration.

Note that clang-format insists on indenting an unrelated comment, I don't know
why.

MozReview-Commit-ID: 7gww3r7t9y4
2017-11-18 07:27:06 +11:00
Nicholas Nethercote
82793cb888 Bug 1418467 - Move pref_ValueChanged() into PrefValue. r=glandium
And invert its sense, renaming as Equals(), because that is easier to think
about.

The patch also reorders some conditions so that
HasDefaultValue()/HasUserValue() is tested before Equals(). This isn't strictly
necessary, but it reads better.

MozReview-Commit-ID: JeGrevDwqKz
2017-11-18 07:19:42 +11:00
Nicholas Nethercote
1dcb3bdf8b Bug 1418156 - Remove unnecessary forward declaration of pref_SetPref(). r=glandium
MozReview-Commit-ID: KQHfpAKEEgt
2017-11-17 16:29:18 +11:00
Nicholas Nethercote
6c9d31a560 Bug 1418156 - Move pref_SetValue() into PrefHashEntry. r=glandium
MozReview-Commit-ID: LE7vQ8Iz5Dg
2017-11-17 16:27:10 +11:00
Nicholas Nethercote
7b03c65950 Bug 1418156 - Rename PrefHashEntry::mKey as mName, and make it private. r=glandium
This requires adding a constructor, which is used in a placement new.

MozReview-Commit-ID: 3v6843D5DMu
2017-11-17 15:57:08 +11:00
Nicholas Nethercote
f5b03a9a0d Bug 1418156 - Move pref_EntryHasAdvisablySizedValues() into PrefHashEntry. r=glandium
MozReview-Commit-ID: 4p0KnaOOi2j
2017-11-17 15:29:30 +11:00
Nicholas Nethercote
7fe41d20c1 Bug 1418156 - Move pref_GetPrefFromEntry into PrefHashEntry. r=glandium
And rename it as ToSetting(). This requires also moving
AssignPrefValueToDomPrefValue into PrefHashEntry.

MozReview-Commit-ID: 8ntNZJt9rhv
2017-11-17 15:29:30 +11:00
Nicholas Nethercote
febff4f877 Bug 1418156 - Overhaul GetPrefValueFromEntry. r=glandium
This patch:

- partially inlines GetPrefValueFromEntry() at its two call sites, to avoid
  repeating the kind check;

- renames it as AssignPrefValueToDomPrefValue().

MozReview-Commit-ID: BUBk3ML6h5O
2017-11-17 15:29:29 +11:00
Nicholas Nethercote
a504f32a64 Bug 1418156 - Move the PLDHashTable ops into PrefHashEntry. r=glandium
MozReview-Commit-ID: HJfjz2PzW0I
2017-11-17 15:29:29 +11:00
Nicholas Nethercote
a7e25e7bc7 Bug 1418156 - Merge PrefTypeFlags into PrefHashEntry. r=glandium
PrefTypeFlags is a class with a lot of smarts (i.e. methods). PrefHashEntry is
a class with little smarts. This is silly, because PrefTypeFlags is essentially
an internal implementation detail of PrefHashEntry.

This patch merges PrefTypeFlags into PrefHashEntry, so that PrefHashEntry has
all the smarts. This means lots of `pref->mPrefFlags.Foo()` calls become
`pref->Foo()`.

The patch also changes the representation of the type and flags within
PrefHashEntry to use bitfields, which avoids the need for a Flags type and is
much simpler than the old approach.

MozReview-Commit-ID: 4Yt9OtBzh9e
2017-11-17 15:29:14 +11:00
Nicholas Nethercote
9734c81a64 Bug 1418156 - Don't zero newly added PrefHashEntrys. r=glandium
They are guaranteed to be zeroed already by PLDHashTable.

MozReview-Commit-ID: LBeGa9ABYc3
2017-11-17 13:30:38 +11:00
Nicholas Nethercote
622b7be0b9 Bug 1418156 - Remove forward declaration of PrefHashEntry. r=glandium
MozReview-Commit-ID: 1KRWnjp9VW4
2017-11-17 13:27:00 +11:00
Nicholas Nethercote
8e8ac9747e Bug 1417806 - Name variables more consistently. r=glandium
Specifically:

- PrefHashEntry --> `pref`
- PrefName      --> `prefName`
- PrefSetting   --> `setting`

MozReview-Commit-ID: CSse2jVro3E
2017-11-16 18:59:27 +11:00
Nicholas Nethercote
660fa961d5 Bug 1417806 - Rename m{User,Default}Pref as m{User,Default}Value.
Because they are the pref's values, not the pref itself.

MozReview-Commit-ID: 1N4Fh2TF8lL
2017-11-16 18:48:08 +11:00
Nicholas Nethercote
8d36e8d95f Bug 1417806 - Avoid "sticky default" terminology. r=glandium
It's the user value that's sticky, not the default value. Though we typically
talk about the entire pref being sticky, so that's what this patch does.

MozReview-Commit-ID: 8THuRCTZ7uw
2017-11-16 16:16:03 +11:00
Nicholas Nethercote
5c672af1d1 Bug 1417806 - Rename kPrefSticky as kStickyPref. r=glandium
This matches the corresponding string "sticky_pref".

MozReview-Commit-ID: 8bqM5x8bIoG
2017-11-16 18:45:53 +11:00
Nicholas Nethercote
c175bfe4aa Bug 1417806 - Rename some things in PrefTypeFlags. r=glandium
So that "default value" and "user value" are used consistently.

MozReview-Commit-ID: Hmfct8STu33
2017-11-16 16:02:07 +11:00
Nicholas Nethercote
f776664638 Bug 1417806 - Move BoolVarChanged() next to AddBoolVarCache(). r=glandium
This makes it like the VarCache functions for int, uint, atomic unit, and float.

MozReview-Commit-ID: 4CRuvAjqGCj
2017-11-16 16:02:07 +11:00
Nicholas Nethercote
4b0cbe18e6 Bug 1417806 - Add a comment about gCacheData. r=glandium
MozReview-Commit-ID: 1oVYUMtobRF
2017-11-16 18:39:00 +11:00
Nicholas Nethercote
8a84dbb66f Bug 1417806 - Reduce gPrefNameArena's alignment to 1. r=glandium.
Because it holds 8-bit strings, which only need 1 byte alignment.

For the profile on my Linux box, in every process this reduces the size of the
arena by 1 chunk, from 120 KiB to 112 KiB.

MozReview-Commit-ID: 8ozrLIq5ZZ4
2017-11-16 16:02:07 +11:00
Nicholas Nethercote
2d93926a86 Bug 1417806 - Overhaul gWatchingPref et al. r=glandium
This patch renames it as gInstallingCallback, adds a comment, and reduces the
scope of the AUTO_INSTALLING_CALLBACK() objects to the minimum.

MozReview-Commit-ID: EGfnBPVFtmw
2017-11-16 16:02:07 +11:00
Nicholas Nethercote
3f1d75113d Bug 1417746 - Overhaul libpref's memory reporter. r=glandium
This splits the measurements into several buckets, like so:

> 718,528 B (00.40%) -- preferences
> ├──262,176 B (00.14%) ── hash-table
> ├──181,952 B (00.10%) ── callbacks
> ├──122,880 B (00.07%) ── pref-name-arena
> ├───91,872 B (00.05%) ── root-branches
> ├───38,296 B (00.02%) ── string-values
> ├───21,272 B (00.01%) ── cache-data
> └───────80 B (00.00%) ── misc

The patch also measures some things that were previously overlooked.

- String pref values. (The old code had a comment that incorrectly claimed they
  were allocated out of an arena.)

- The PrefCallback objects pointed to by entries in nsPrefBranch::mObservers.

And it makes the code more like typical reporters.

- It removes the "AndOtherStuff" from Preferences' measuring method, and
  measuring those global structures in
  PreferenceServiceReporter::CollectReports().

- It adds `const` where appropriate.

MozReview-Commit-ID: dyNg7ldQdh
2017-11-16 15:55:58 +11:00
Nicholas Nethercote
d48d7af93b Bug 1416638 - Inline and remove PREF_Get*(). r=glandium.
MozReview-Commit-ID: CiCKpihJJJF
2017-11-14 19:06:02 +11:00
Nicholas Nethercote
318c4f45cf Bug 1416638 - Inline and remove PREF_Set*(). r=glandium.
This patch also adds some Set*InAnyProcess() methods, and makes nsPrefBranch a
friend of Preferences so it can call those methods.

And it moves the thin Set*() wrapper functions to Preferences.h, alongside
SetUint().

MozReview-Commit-ID: 88HhmcTFZNc
2017-11-14 19:06:02 +11:00
Nicholas Nethercote
b64aba3f63 Bug 1416638 - Rename SetCharPrefInternal() as SetCharPrefNoLengthCheck(). r=glandium.
Because it's clearer.

MozReview-Commit-ID: 4zfDnsaPQSK
2017-11-14 19:06:02 +11:00
Nicholas Nethercote
4d87903d13 Bug 1416638 - Move a couple of functions into Preferences. r=glandium.
This will allow other functions to be moved into Preferences and be marked as
`private` in subsequent patches.

The patch also renames SetPrefValue() as SetValueFromDom(), because that's a
clearer name.

MozReview-Commit-ID: CB1xmPSmac6
2017-11-14 19:06:02 +11:00
Nicholas Nethercote
239fcd0ea0 Bug 1416638 - Change nsPrefBranch mIsDefault to a PrefValueKind. r=glandium.
This makes the next patches nicer.

MozReview-Commit-ID: 8EoAkmmMavY
2017-11-14 19:06:02 +11:00
Nicholas Nethercote
45164b6a68 Bug 1416638 - Add a PrefValueKind arg to Preferences::Get*(), and remove Preferences::GetDefault*(). r=glandium
MozReview-Commit-ID: LgnZAf1pAl1
2017-11-14 19:06:01 +11:00
Nicholas Nethercote
4cc62dcfa6 Bug 1416638 - Add a PrefValueKind arg to Preferences::Set*(). r=glandium
This is unused for now, but will be necessary for nsPrefBranch::Set*() to call
into Preferences::Set*().

The patch also renames some arguments from aPref to aPrefName, because that's a
better name.

MozReview-Commit-ID: 2OPB7CHOgpw
2017-11-13 09:20:45 +11:00
Nicholas Nethercote
03510e576d Bug 1416638 - Introduce PrefValueKind. r=glandium
This is nicer than a bool for tracking the Default vs. User distinction, and it
replaces the Preferences.cpp-only WhichValue type.

MozReview-Commit-ID: 8CrdDN2vBJQ
2017-11-13 09:20:42 +11:00
Nicholas Nethercote
91c86b10c2 Bug 1416622 - Tighten up libpref's process checking. r=glandium
libpref only allows pref modifications in the parent process. This patch
tightens up the checking, which is a bit inconsistent.

- It removes ENSURE_MAIN_PROCESS_WITH_WARNING, which does NS_WARNING on
  failure, and replaces its uses with ENSURE_MAIN_PROCESS, which does NS_ERROR
  on failure. This required adding an XRE_IsParentProcess() check to one place
  in editor/.

- It converts XRE_IsContentProcess() tests to !XRE_IsParentProcess(), because
  we now have multiple kinds of non-parent process.

- It uses ENSURE_MAIN_PROCESS to replace other checking code in a few places.

- It improves a comment in HandleDirty().

MozReview-Commit-ID: D8znQWH7ery
2017-11-13 09:19:55 +11:00
Nicholas Nethercote
dc6aeedfb6 Bug 1416613 - Replace use of std::string and std::vector with Mozilla equivalents. r=glandium
MozReview-Commit-ID: 1Zcuespd4sn
2017-11-14 19:06:01 +11:00
Nicholas Nethercote
f206bf46ce Bug 1416613 - Make Preferences::InitStaticMembers() slightly faster. r=glandium
InitStaticMembers() is the hottest function within libpref, because it is
called from all the getters and setters. This patch tweaks it so the common
case is handled with a single comparison, instead of two. This is valid because
sPreferences is nulled at the same time that sShutdown is set.

The patch also tweaks some other conditions to take advantage of this fact.

MozReview-Commit-ID: C74fLWOw7bE
2017-11-13 09:19:49 +11:00
Nicholas Nethercote
abd3fc983b Bug 1415799 - Rename pref_HashPref() as pref_SetPref(). r=glandium.
Because it sets the pref.

MozReview-Commit-ID: IlEVRWKU94X
2017-11-09 18:00:42 +11:00
Nicholas Nethercote
3f99320f1c Bug 1415799 - Inline and remove Preferences::Init(). r=glandium
It has a single call site.

MozReview-Commit-ID: A96MRRa3W5N
2017-11-09 17:59:51 +11:00
Nicholas Nethercote
bb01adc954 Bug 1415799 - Remove PREF_ClearUserPref() forward declaration. r=glandium
It's not needed.

MozReview-Commit-ID: AqKeBuxZJh3
2017-11-09 17:59:12 +11:00
Nicholas Nethercote
da715770fb Bug 1415799 - Inline and remove PREF_Init() and PREF_CleanupPrefs(). r=glandium
They both have two callsites, but in one of those they appear together, where
much of the code can be replaced with a ClearAndPrepareForLength() call.

MozReview-Commit-ID: 1A771gsHWan
2017-11-09 17:58:35 +11:00
Nicholas Nethercote
bc8af2c4f1 Bug 1415799 - Inline and remove PREF_Cleanup. r=glandium
It has a single call site.

MozReview-Commit-ID: DoE5BlEA9a6
2017-11-09 17:56:29 +11:00
Nicholas Nethercote
ff85d51fcc Bug 1415799 - Inline and remove pref_SizeOfPrivateData(). r=glandium
It has a single call site.

MozReview-Commit-ID: DhpO2vyeC61
2017-11-09 17:54:32 +11:00
Nicholas Nethercote
2c805ac89f Bug 1414096 (attempt 2) - Remove support for nsISupportsString values in nsPrefBranch::{get,set}ComplexValue(). r=florian.
Bug 1345294 introduced nsPrefBranch::{get,set}StringPref(), which allowed the
getting of utf8 strings from prefs, which previously required using
nsISupportsString with {get,set}ComplexValue. That bug also converted most
uses.

This patch finishes the job.

- It removes the nsISupportsString support.

- It converts existing code that relied on the nsISupportsString.

- It removes the lint that was set up to detect such uses of nsISupportsString.
2017-11-10 09:07:48 +11:00
Narcis Beleuzu
2d99ba07ef Backed out 1 changesets (bug 1414096) for dt1 failures "devtools/client/commandline/test/browser_cmd_pref3.js" r=backout on a CLOSED TREE
Backed out changeset e843de356b7e (bug 1414096)
2017-11-08 18:04:01 +02:00
Jonathan Watt
ac76b20848 Bug 1411552 - Improve the warning about attempting to overwrite prefs with a pref of the wrong type. r=njn
MozReview-Commit-ID: AAlimIWoOgQ
2017-10-11 19:10:43 +01:00
Nicholas Nethercote
9bd88a7074 Bug 1414188 - Remove ValueObserver. r=glandium.
libpref has callbacks. You can register a callback function against a
particular pref (or pref prefix), and it'll be called when any matching pref
changes.

This is implemented in two layers. The lower layer is the list of CallbackNode
objects, pointed to by gFirstCallback.

The upper layer involves gObserverTable, which is a hash table of ValueObserver
objects. It is used for callbacks registered via
Preferences::RegisterCallback() and Preferences::Add*VarCache(), but not for
observers registered with Preferences::Add{Weak,Strong}Observer(). If multiple
callbacks with identical prefnames, callback functions and MatchKinds occur,
they are commoned up into a single ValueObserver, which is then wrapped by a
single CallbackNode. (The callbacks within a single ValueObserver can have
different void* aClosure args; ValueObserver keeps those in an nsTArray.)

Note also that gObserverTable is very inelegant, with duplication of data
between the keys and the values due it being a
nsRefPtrHashtable<ValueObserverHashKey, ValueObserver> and ValueObserver being
a subclass of ValueObserverHashKey(!)

This extra layer might make sense if there were a lot of commoning up
happening, but there's not. Across all process kinds there is an average of
between 1.2 and 1.7 closures per ValueObserver. The vast majority have 1
closure, and there are a handful that have multiple; the highest number I've
seen is 71.

(Note that this two-layer design probably seemed more natural back when libpref
was spread across multiple files.)

This patch removes the ValueObserver layer. The only tricky part is that there
is a notion of a MatchKind -- ExactMatch or PrefixMatch -- which exists in the
ValueObserverLayer but not in the CallbackNode layer. So the patch moves the
MatchKind into the CallbackNode layer, which is straightforward.

On Linux64 this reduces memory usage by about 40 KiB in the parent process and
about 30 KiB in each content processes.

The performance implications are minor.

- The list of CallbackNodes is a bit longer, so when a pref is changed we must
  check more nodes. But we avoid possibly doing prefname matching twice.

- Callback registration is much faster, just a simple list prepend, without any
  hash table insertion required.

- Callback unregistration is probably not much different. There is a longer
  list to traverse, but no hash table removal.

- Pref lookup is by far the hottest libpref operation, and it's unchanged.

For perf to be genuinely affected would require (a) a *lot* more
almost-duplicate callbacks that would have been commoned up, and (b) frequent
changing of the pref those callbacks are observing. This seems highly unlikely.

MozReview-Commit-ID: 6xo4xmytOf3
2017-11-02 20:38:34 +11:00
Nicholas Nethercote
44eb7f0274 Bug 1414096 - Remove support for nsISupportsString values in nsPrefBranch::{get,set}ComplexValue(). r=florian.
Bug 1345294 introduced nsPrefBranch::{get,set}StringPref(), which allowed the
getting of utf8 strings from prefs, which previously required using
nsISupportsString with {get,set}ComplexValue. That bug also converted most
uses.

This patch finishes the job.

- It removes the nsISupportsString support.

- It converts existing code that relied on the nsISupportsString.

- It removes the lint that was set up to detect such uses of nsISupportsString.
2017-10-31 16:34:35 +11:00
Nicholas Nethercote
cae40186f8 Bug 1413811 (part 3) - Rename RegisterPriorityCallback(). r=glandium.
MozReview-Commit-ID: 5Ov1cHgfB5Y
2017-11-02 17:20:36 +11:00
Nicholas Nethercote
2fe3def9e3 Bug 1413811 (part 2) - Factor out similarities between RegisterPriorityCallback() and Preferences::RegisterCallback(). r=glandium.
MozReview-Commit-ID: 8K3RNjZTSc3
2017-11-02 17:13:47 +11:00