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

Side by Side Diff: Source/wtf/StackBounds.h

Issue 13890009: Simplify StackBounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 7 years, 8 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 | Source/wtf/StackStats.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, 2013 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2010, 2013 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 { 45 {
46 StackBounds bounds; 46 StackBounds bounds;
47 bounds.initialize(); 47 bounds.initialize();
48 bounds.checkConsistency(); 48 bounds.checkConsistency();
49 return bounds; 49 return bounds;
50 } 50 }
51 51
52 bool isSafeToRecurse(size_t minAvailableDelta = s_defaultAvailabilityDelta) const 52 bool isSafeToRecurse(size_t minAvailableDelta = s_defaultAvailabilityDelta) const
53 { 53 {
54 checkConsistency(); 54 checkConsistency();
55 if (isGrowingDownward()) 55 return current() >= recursionLimit(minAvailableDelta);
56 return current() >= recursionLimit(minAvailableDelta);
57 return current() <= recursionLimit(minAvailableDelta);
58 } 56 }
59 57
60 void* origin() const 58 void* origin() const
61 { 59 {
62 ASSERT(m_origin); 60 ASSERT(m_origin);
63 return m_origin; 61 return m_origin;
64 } 62 }
65 63
66 size_t size() const 64 size_t size() const
67 { 65 {
68 if (isGrowingDownward()) 66 return static_cast<char*>(m_origin) - static_cast<char*>(m_bound);
69 return static_cast<char*>(m_origin) - static_cast<char*>(m_bound);
70 return static_cast<char*>(m_bound) - static_cast<char*>(m_origin);
71 } 67 }
72 68
73 private: 69 private:
74 StackBounds() 70 StackBounds()
75 : m_origin(0) 71 : m_origin(0)
76 , m_bound(0) 72 , m_bound(0)
77 { 73 {
78 } 74 }
79 75
80 void initialize(); 76 void initialize();
81 77
82 void* current() const 78 void* current() const
83 { 79 {
84 checkConsistency(); 80 checkConsistency();
85 void* currentPosition = &currentPosition; 81 void* currentPosition = &currentPosition;
86 return currentPosition; 82 return currentPosition;
87 } 83 }
88 84
89 void* recursionLimit(size_t minAvailableDelta = s_defaultAvailabilityDelta) const 85 void* recursionLimit(size_t minAvailableDelta = s_defaultAvailabilityDelta) const
90 { 86 {
91 checkConsistency(); 87 checkConsistency();
92 if (isGrowingDownward()) 88 return static_cast<char*>(m_bound) + minAvailableDelta;
93 return static_cast<char*>(m_bound) + minAvailableDelta;
94 return static_cast<char*>(m_bound) - minAvailableDelta;
95 }
96
97 bool isGrowingDownward() const
98 {
99 ASSERT(m_origin && m_bound);
100 return true;
101 } 89 }
102 90
103 void checkConsistency() const 91 void checkConsistency() const
104 { 92 {
105 #if !ASSERT_DISABLED 93 #if !ASSERT_DISABLED
106 void* currentPosition = &currentPosition; 94 void* currentPosition = &currentPosition;
107 ASSERT(m_origin != m_bound); 95 ASSERT(m_origin != m_bound);
108 ASSERT(isGrowingDownward() 96 ASSERT(currentPosition < m_origin && currentPosition > m_bound);
109 ? (currentPosition < m_origin && currentPosition > m_bound)
110 : (currentPosition > m_origin && currentPosition < m_bound));
111 #endif 97 #endif
112 } 98 }
113 99
114 void* m_origin; 100 void* m_origin;
115 void* m_bound; 101 void* m_bound;
116 102
117 friend class StackStats; 103 friend class StackStats;
118 }; 104 };
119 105
120 } // namespace WTF 106 } // namespace WTF
121 107
122 using WTF::StackBounds; 108 using WTF::StackBounds;
123 109
124 #endif 110 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/StackStats.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698