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

Side by Side Diff: third_party/WebKit/Source/core/css/MediaQuery.cpp

Issue 2837023005: Move MediaQuery classes off BlinkGC heap (Closed)
Patch Set: fix Created 3 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
OLDNEW
1 /* 1 /*
2 * CSS Media Query 2 * CSS Media Query
3 * 3 *
4 * Copyright (C) 2005, 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. 4 * Copyright (C) 2005, 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>.
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (expressions_.IsEmpty()) { 54 if (expressions_.IsEmpty()) {
55 result.Append(media_type_); 55 result.Append(media_type_);
56 return result.ToString(); 56 return result.ToString();
57 } 57 }
58 58
59 if (media_type_ != MediaTypeNames::all || restrictor_ != kNone) { 59 if (media_type_ != MediaTypeNames::all || restrictor_ != kNone) {
60 result.Append(media_type_); 60 result.Append(media_type_);
61 result.Append(" and "); 61 result.Append(" and ");
62 } 62 }
63 63
64 result.Append(expressions_.at(0)->Serialize()); 64 result.Append(expressions_.at(0).Serialize());
65 for (size_t i = 1; i < expressions_.size(); ++i) { 65 for (size_t i = 1; i < expressions_.size(); ++i) {
66 result.Append(" and "); 66 result.Append(" and ");
67 result.Append(expressions_.at(i)->Serialize()); 67 result.Append(expressions_.at(i).Serialize());
68 } 68 }
69 return result.ToString(); 69 return result.ToString();
70 } 70 }
71 71
72 static bool ExpressionCompare(const Member<MediaQueryExp>& a, 72 static bool ExpressionCompare(const MediaQueryExp& a, const MediaQueryExp& b) {
73 const Member<MediaQueryExp>& b) { 73 return CodePointCompare(a.Serialize(), b.Serialize()) < 0;
74 return CodePointCompare(a->Serialize(), b->Serialize()) < 0;
75 } 74 }
76 75
77 MediaQuery* MediaQuery::CreateNotAll() { 76 std::unique_ptr<MediaQuery> MediaQuery::CreateNotAll() {
78 return new MediaQuery(MediaQuery::kNot, MediaTypeNames::all, 77 return WTF::WrapUnique(new MediaQuery(MediaQuery::kNot, MediaTypeNames::all,
79 ExpressionHeapVector()); 78 ExpressionHeapVector()));
80 } 79 }
81 80
82 MediaQuery* MediaQuery::Create(RestrictorType restrictor, 81 std::unique_ptr<MediaQuery> MediaQuery::Create(
83 String media_type, 82 RestrictorType restrictor,
84 ExpressionHeapVector expressions) { 83 String media_type,
85 return new MediaQuery(restrictor, std::move(media_type), 84 ExpressionHeapVector expressions) {
86 std::move(expressions)); 85 return WTF::WrapUnique(new MediaQuery(restrictor, std::move(media_type),
86 std::move(expressions)));
87 } 87 }
88 88
89 MediaQuery::MediaQuery(RestrictorType restrictor, 89 MediaQuery::MediaQuery(RestrictorType restrictor,
90 String media_type, 90 String media_type,
91 ExpressionHeapVector expressions) 91 ExpressionHeapVector expressions)
92 : restrictor_(restrictor), 92 : restrictor_(restrictor),
93 media_type_(AttemptStaticStringCreation(media_type.DeprecatedLower())), 93 media_type_(AttemptStaticStringCreation(media_type.DeprecatedLower())),
94 expressions_(std::move(expressions)) { 94 expressions_(std::move(expressions)) {
95 NonCopyingSort(expressions_.begin(), expressions_.end(), ExpressionCompare); 95 NonCopyingSort(expressions_.begin(), expressions_.end(), ExpressionCompare);
96 96
97 // Remove all duplicated expressions. 97 // Remove all duplicated expressions.
98 MediaQueryExp* key = 0; 98 MediaQueryExp key = MediaQueryExp::Invalid();
99 for (int i = expressions_.size() - 1; i >= 0; --i) { 99 for (int i = expressions_.size() - 1; i >= 0; --i) {
100 MediaQueryExp* exp = expressions_.at(i).Get(); 100 MediaQueryExp exp = expressions_.at(i);
101 101 CHECK(exp.IsValid());
102 if (key && *exp == *key) 102 CHECK(String() == String());
sof 2017/04/26 09:16:11 accidental addition?
keishi 2017/04/26 09:44:35 Oops. Sorry.
103 if (exp == key)
103 expressions_.erase(i); 104 expressions_.erase(i);
104 else 105 else
105 key = exp; 106 key = exp;
106 } 107 }
107 } 108 }
108 109
109 MediaQuery::MediaQuery(const MediaQuery& o) 110 MediaQuery::MediaQuery(const MediaQuery& o)
110 : restrictor_(o.restrictor_), 111 : restrictor_(o.restrictor_),
111 media_type_(o.media_type_), 112 media_type_(o.media_type_),
112 serialization_cache_(o.serialization_cache_) { 113 serialization_cache_(o.serialization_cache_) {
113 expressions_.ReserveInitialCapacity(o.expressions_.size()); 114 expressions_.ReserveInitialCapacity(o.expressions_.size());
114 for (unsigned i = 0; i < o.expressions_.size(); ++i) 115 for (unsigned i = 0; i < o.expressions_.size(); ++i)
115 expressions_.push_back(o.expressions_[i]->Copy()); 116 expressions_.push_back(o.expressions_[i]);
116 } 117 }
117 118
118 MediaQuery::~MediaQuery() {} 119 MediaQuery::~MediaQuery() {}
119 120
120 // http://dev.w3.org/csswg/cssom/#compare-media-queries 121 // http://dev.w3.org/csswg/cssom/#compare-media-queries
121 bool MediaQuery::operator==(const MediaQuery& other) const { 122 bool MediaQuery::operator==(const MediaQuery& other) const {
122 return CssText() == other.CssText(); 123 return CssText() == other.CssText();
123 } 124 }
124 125
125 // http://dev.w3.org/csswg/cssom/#serialize-a-list-of-media-queries 126 // http://dev.w3.org/csswg/cssom/#serialize-a-list-of-media-queries
126 String MediaQuery::CssText() const { 127 String MediaQuery::CssText() const {
127 if (serialization_cache_.IsNull()) 128 if (serialization_cache_.IsNull())
128 const_cast<MediaQuery*>(this)->serialization_cache_ = Serialize(); 129 const_cast<MediaQuery*>(this)->serialization_cache_ = Serialize();
129 130
130 return serialization_cache_; 131 return serialization_cache_;
131 } 132 }
132 133
133 DEFINE_TRACE(MediaQuery) {
134 visitor->Trace(expressions_);
135 }
136
137 } // namespace blink 134 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698