Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: third_party/WebKit/Source/platform/ScriptForbiddenScope.h

Issue 2709763003: Avoid calling isMainThread() in the common cases when checking ScriptForbiddenScope::isScriptForbid… (Closed)
Patch Set: english. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ScriptForbiddenScope_h 5 #ifndef ScriptForbiddenScope_h
6 #define ScriptForbiddenScope_h 6 #define ScriptForbiddenScope_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "wtf/Allocator.h" 9 #include "wtf/Allocator.h"
10 #include "wtf/AutoReset.h" 10 #include "wtf/AutoReset.h"
(...skipping 26 matching lines...) Expand all
37 37
38 private: 38 private:
39 Optional<AutoReset<unsigned>> m_change; 39 Optional<AutoReset<unsigned>> m_change;
40 }; 40 };
41 41
42 static void enter() { 42 static void enter() {
43 DCHECK(isMainThread()); 43 DCHECK(isMainThread());
44 ++s_scriptForbiddenCount; 44 ++s_scriptForbiddenCount;
45 } 45 }
46 static void exit() { 46 static void exit() {
47 DCHECK(isMainThread());
47 DCHECK(s_scriptForbiddenCount); 48 DCHECK(s_scriptForbiddenCount);
48 --s_scriptForbiddenCount; 49 --s_scriptForbiddenCount;
49 } 50 }
50 static bool isScriptForbidden() { 51 static bool isScriptForbidden() {
51 return isMainThread() && s_scriptForbiddenCount; 52 // Check s_scriptForbiddenCount first to avoid any calls to isMainThread()
53 // since under normal situations where we check this (ex. inside
54 // V8ScriptRunner) the value should always be zero.
55 return s_scriptForbiddenCount && isMainThread();
52 } 56 }
53 57
54 private: 58 private:
55 static unsigned s_scriptForbiddenCount; 59 static unsigned s_scriptForbiddenCount;
56 }; 60 };
57 61
58 // Scoped disabling of script execution on the main thread, 62 // Scoped disabling of script execution on the main thread,
59 // if called on the main thread. 63 // if called on the main thread.
60 // 64 //
61 // No effect when used by from other threads -- simplifies 65 // No effect when used by from other threads -- simplifies
(...skipping 13 matching lines...) Expand all
75 ~ScriptForbiddenIfMainThreadScope() { 79 ~ScriptForbiddenIfMainThreadScope() {
76 if (m_IsMainThread) 80 if (m_IsMainThread)
77 ScriptForbiddenScope::exit(); 81 ScriptForbiddenScope::exit();
78 } 82 }
79 bool m_IsMainThread; 83 bool m_IsMainThread;
80 }; 84 };
81 85
82 } // namespace blink 86 } // namespace blink
83 87
84 #endif // ScriptForbiddenScope_h 88 #endif // ScriptForbiddenScope_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698