forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start BindStateBase ref count from 1 instead of 0
The first atomic increments of ref counts are generally unneeded if the ref count starts from 1 instead of 0, and we can detect an invalid AddRef from 0 to 1 in that case. Especially, the ref count in BindStateBase is incremented 300k times in its constructor by the first page load from the browser boot, and also it sometimes hits invalid state. Note that 300k atomic increments are probably not so time consuming as we can measure. This CL adds `base::AdoptRef` to scoped_refptr for ref counted types whose ref count start from 1, and converts BindStateBase to use it. Review-Url: https://codereview.chromium.org/2723423002 Cr-Commit-Position: refs/heads/master@{#461372}
- Loading branch information
Showing
8 changed files
with
209 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/memory/ref_counted.h" | ||
|
||
namespace base { | ||
|
||
class InitialRefCountIsZero : public base::RefCounted<InitialRefCountIsZero> { | ||
public: | ||
InitialRefCountIsZero() {} | ||
private: | ||
friend class base::RefCounted<InitialRefCountIsZero>; | ||
~InitialRefCountIsZero() {} | ||
}; | ||
|
||
#if defined(NCTEST_ADOPT_REF_TO_ZERO_START) // [r"fatal error: static_assert failed \"Use AdoptRef only for the reference count starts from one\.\""] | ||
|
||
void WontCompile() { | ||
AdoptRef(new InitialRefCountIsZero()); | ||
} | ||
|
||
#endif | ||
|
||
} // namespace base |