summaryrefslogtreecommitdiff
path: root/Source/WebCore/css/CSSSelectorList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/css/CSSSelectorList.cpp')
-rw-r--r--Source/WebCore/css/CSSSelectorList.cpp62
1 files changed, 35 insertions, 27 deletions
diff --git a/Source/WebCore/css/CSSSelectorList.cpp b/Source/WebCore/css/CSSSelectorList.cpp
index 661a4f2d2..fd7e13410 100644
--- a/Source/WebCore/css/CSSSelectorList.cpp
+++ b/Source/WebCore/css/CSSSelectorList.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2012, 2013, 2014 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,16 +27,11 @@
#include "config.h"
#include "CSSSelectorList.h"
-#include "CSSParserValues.h"
+#include "CSSParserSelector.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
-CSSSelectorList::~CSSSelectorList()
-{
- deleteSelectors();
-}
-
CSSSelectorList::CSSSelectorList(const CSSSelectorList& other)
{
unsigned otherComponentCount = other.componentCount();
@@ -47,16 +42,13 @@ CSSSelectorList::CSSSelectorList(const CSSSelectorList& other)
new (NotNull, &m_selectorArray[i]) CSSSelector(other.m_selectorArray[i]);
}
-void CSSSelectorList::adopt(CSSSelectorList& list)
+CSSSelectorList::CSSSelectorList(CSSSelectorList&& other)
+ : m_selectorArray(other.m_selectorArray)
{
- deleteSelectors();
- m_selectorArray = list.m_selectorArray;
- list.m_selectorArray = 0;
-
- ASSERT_WITH_SECURITY_IMPLICATION(componentCount());
+ other.m_selectorArray = nullptr;
}
-void CSSSelectorList::adoptSelectorVector(Vector<OwnPtr<CSSParserSelector>>& selectorVector)
+void CSSSelectorList::adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector)
{
ASSERT_WITH_SECURITY_IMPLICATION(!selectorVector.isEmpty());
@@ -74,7 +66,7 @@ void CSSSelectorList::adoptSelectorVector(Vector<OwnPtr<CSSParserSelector>>& sel
while (current) {
{
// Move item from the parser selector vector into m_selectorArray without invoking destructor (Ugh.)
- CSSSelector* currentSelector = current->releaseSelector().leakPtr();
+ CSSSelector* currentSelector = current->releaseSelector().release();
memcpy(&m_selectorArray[arrayIndex], currentSelector, sizeof(CSSSelector));
// Free the underlying memory without invoking the destructor.
@@ -103,30 +95,46 @@ unsigned CSSSelectorList::componentCount() const
return (current - m_selectorArray) + 1;
}
+CSSSelectorList& CSSSelectorList::operator=(CSSSelectorList&& other)
+{
+ deleteSelectors();
+ m_selectorArray = other.m_selectorArray;
+ other.m_selectorArray = nullptr;
+
+ return *this;
+}
+
void CSSSelectorList::deleteSelectors()
{
if (!m_selectorArray)
return;
- for (CSSSelector* s = m_selectorArray; ; ++s) {
+ CSSSelector* selectorArray = m_selectorArray;
+ m_selectorArray = nullptr;
+
+ bool isLastSelector = false;
+ for (CSSSelector* s = selectorArray; !isLastSelector; ++s) {
+ isLastSelector = s->isLastInSelectorList();
s->~CSSSelector();
- if (s->isLastInSelectorList())
- break;
}
- fastFree(m_selectorArray);
+ fastFree(selectorArray);
}
String CSSSelectorList::selectorsText() const
{
StringBuilder result;
+ buildSelectorsText(result);
+ return result.toString();
+}
- for (const CSSSelector* s = first(); s; s = next(s)) {
- if (s != first())
- result.append(", ");
- result.append(s->selectorText());
+void CSSSelectorList::buildSelectorsText(StringBuilder& stringBuilder) const
+{
+ const CSSSelector* firstSubselector = first();
+ for (const CSSSelector* subSelector = firstSubselector; subSelector; subSelector = CSSSelectorList::next(subSelector)) {
+ if (subSelector != firstSubselector)
+ stringBuilder.appendLiteral(", ");
+ stringBuilder.append(subSelector->selectorText());
}
-
- return result.toString();
}
template <typename Functor>
@@ -163,9 +171,9 @@ class SelectorNeedsNamespaceResolutionFunctor {
public:
bool operator()(const CSSSelector* selector)
{
- if (selector->m_match == CSSSelector::Tag && selector->tagQName().prefix() != nullAtom && selector->tagQName().prefix() != starAtom)
+ if (selector->match() == CSSSelector::Tag && !selector->tagQName().prefix().isEmpty() && selector->tagQName().prefix() != starAtom)
return true;
- if (selector->isAttributeSelector() && selector->attribute().prefix() != nullAtom && selector->attribute().prefix() != starAtom)
+ if (selector->isAttributeSelector() && !selector->attribute().prefix().isEmpty() && selector->attribute().prefix() != starAtom)
return true;
return false;
}