mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1558440 - Use SaturateUint32 for the visible content heuristic. r=bzbarsky
Turns out we do have saturated arithmetic in mfbt, I just missed it. Also, use just an uint32 for the heuristic. Text length is a uint32 anyway, and it's unlikely we want to decide anything when the value is over the max uint32 value. Differential Revision: https://phabricator.services.mozilla.com/D34496 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
dee0e36659
commit
53fa6bd77e
@ -9,6 +9,7 @@
|
||||
#include "mozilla/EventStates.h" // for EventStates
|
||||
#include "mozilla/FlushType.h" // for enum
|
||||
#include "mozilla/Pair.h" // for Pair
|
||||
#include "mozilla/Saturate.h" // for SaturateUint32
|
||||
#include "nsAutoPtr.h" // for member
|
||||
#include "nsCOMArray.h" // for member
|
||||
#include "nsCompatibility.h" // for member
|
||||
@ -3699,15 +3700,13 @@ class Document : public nsINode,
|
||||
|
||||
void PropagateUseCounters(Document* aParentDocument);
|
||||
|
||||
void AddToVisibleContentHeuristic(size_t aNumber) {
|
||||
if (MOZ_UNLIKELY(SIZE_MAX - mVisibleContentHeuristic < aNumber)) {
|
||||
mVisibleContentHeuristic = SIZE_MAX;
|
||||
} else {
|
||||
mVisibleContentHeuristic += aNumber;
|
||||
}
|
||||
void AddToVisibleContentHeuristic(uint32_t aNumber) {
|
||||
mVisibleContentHeuristic += aNumber;
|
||||
}
|
||||
|
||||
size_t GetVisibleContentHeuristic() const { return mVisibleContentHeuristic; }
|
||||
uint32_t GetVisibleContentHeuristic() const {
|
||||
return mVisibleContentHeuristic.value();
|
||||
}
|
||||
|
||||
// Called to track whether this document has had any interaction.
|
||||
// This is used to track whether we should permit "beforeunload".
|
||||
@ -4913,7 +4912,7 @@ class Document : public nsINode,
|
||||
// <style>.
|
||||
//
|
||||
// Note that this is only measured during load.
|
||||
size_t mVisibleContentHeuristic = 0;
|
||||
SaturateUint32 mVisibleContentHeuristic{0};
|
||||
|
||||
// Whether the user has interacted with the document or not:
|
||||
bool mUserHasInteracted;
|
||||
|
@ -114,7 +114,7 @@ class SaturateOp {
|
||||
|
||||
/**
|
||||
* |Saturate<T>| is a value type for saturation arithmetics. It's
|
||||
* build on top of |SaturateOp<T>|.
|
||||
* built on top of |SaturateOp<T>|.
|
||||
*/
|
||||
template <typename T>
|
||||
class Saturate {
|
||||
|
Loading…
Reference in New Issue
Block a user