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

Unified Diff: Source/wtf/LinkedStack.h

Issue 17314010: RuleSet causes 600 kB of memory fragmentation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/wtf/LinkedStack.h
diff --git a/public/web/WebInbandTextTrack.h b/Source/wtf/LinkedStack.h
similarity index 58%
copy from public/web/WebInbandTextTrack.h
copy to Source/wtf/LinkedStack.h
index cebdf20b8552aee6e4cc4977ebcf6cb7ebbc1e02..a8bc2e1be4c157b8442436820dc3701c097ad85d 100644
--- a/public/web/WebInbandTextTrack.h
+++ b/Source/wtf/LinkedStack.h
@@ -28,49 +28,82 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef WebInbandTextTrack_h
-#define WebInbandTextTrack_h
+#ifndef LinkedStack_h
esprehn 2013/06/20 22:29:52 I hate the git diff similarity stuff :/
+#define LinkedStack_h
-namespace WebKit {
+#include "wtf/OwnPtr.h"
-class WebString;
-class WebInbandTextTrackClient;
+namespace WTF {
-class WebInbandTextTrack {
+template <typename T>
+class LinkedStack {
public:
- enum Kind {
- KindSubtitles,
- KindCaptions,
- KindDescriptions,
- KindChapters,
- KindMetadata,
- KindNone
- };
+ LinkedStack() { }
esprehn 2013/06/20 22:29:52 You can leave this out, we can use the default one
abarth-chromium 2013/06/20 22:52:32 Very true.
+
+ bool isEmpty();
+
+ void push(const T&);
+ const T& peek();
+ void pop();
+
+ size_t size();
+
+private:
+ struct Node {
+ Node(const T&, PassOwnPtr<Node> next);
- enum Mode {
- ModeDisabled,
- ModeHidden,
- ModeShowing
+ T m_data;
+ OwnPtr<Node> m_next;
};
- virtual ~WebInbandTextTrack() {}
+ OwnPtr<Node> m_head;
+};
- virtual void setClient(WebInbandTextTrackClient*) = 0;
- virtual WebInbandTextTrackClient* client() = 0;
+template <typename T>
+LinkedStack<T>::Node::Node(const T& data, PassOwnPtr<Node> next)
+ : m_data(data)
+ , m_next(next)
+{
+}
- virtual void setMode(Mode) = 0;
- virtual Mode mode() const = 0;
+template <typename T>
+inline bool LinkedStack<T>::isEmpty()
+{
+ return !m_head;
+}
- virtual Kind kind() const = 0;
- virtual bool isClosedCaptions() const = 0;
+template <typename T>
+inline void LinkedStack<T>::push(const T& data)
+{
+ m_head = adoptPtr(new Node(data, m_head.release()));
+}
- virtual WebString label() const = 0;
- virtual WebString language() const = 0;
- virtual bool isDefault() const = 0;
+template <typename T>
+inline const T& LinkedStack<T>::peek()
+{
+ return m_head->m_data;
+}
- virtual int textTrackIndex() const = 0;
-};
+template <typename T>
+inline void LinkedStack<T>::pop()
+{
+ m_head = m_head->m_next.release();
+}
+
+template <typename T>
+inline size_t LinkedStack<T>::size()
esprehn 2013/06/20 22:29:52 I'd rather we just store the size inside here. Hav
abarth-chromium 2013/06/20 22:52:32 Ok.
+{
+ size_t result = 0;
+ Node* current = m_head.get();
+ while (current) {
+ ++result;
+ current = current->m_next.get();
+ }
+ return result;
+}
+
+}
-} // namespace WebKit
+using WTF::LinkedStack;
#endif

Powered by Google App Engine
This is Rietveld 408576698