Diff
Modified: trunk/Source/WebCore/ChangeLog (184565 => 184566)
--- trunk/Source/WebCore/ChangeLog 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/ChangeLog 2015-05-19 16:29:37 UTC (rev 184566)
@@ -1,3 +1,42 @@
+2015-05-19 Hunseop Jeong <[email protected]>
+
+ Use modern for-loops in WebCore/xml.
+ https://bugs.webkit.org/show_bug.cgi?id=145046
+
+ Reviewed by Chris Dumez.
+
+ No new tests, no new tests.
+
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::uppercaseKnownHTTPMethod):
+ * xml/XPathExpressionNode.cpp:
+ (WebCore::XPath::_expression_::setSubexpressions):
+ * xml/XPathFunctions.cpp:
+ (WebCore::XPath::FunSum::evaluate):
+ (WebCore::XPath::populateFunctionMap):
+ * xml/XPathNodeSet.cpp:
+ (WebCore::XPath::NodeSet::traversalSort):
+ * xml/XPathParser.cpp:
+ (WebCore::XPath::populateAxisNamesMap):
+ * xml/XPathPath.cpp:
+ (WebCore::XPath::Filter::evaluate):
+ (WebCore::XPath::LocationPath::evaluate):
+ * xml/XPathPredicate.cpp:
+ (WebCore::XPath::EqTestOp::compare):
+ (WebCore::XPath::Union::evaluate):
+ * xml/XPathStep.cpp:
+ (WebCore::XPath::Step::optimize):
+ (WebCore::XPath::Step::predicatesAreContextListInsensitive):
+ (WebCore::XPath::Step::evaluate):
+ (WebCore::XPath::nodeMatches):
+ * xml/XSLStyleSheetLibxslt.cpp:
+ (WebCore::XSLStyleSheet::~XSLStyleSheet):
+ (WebCore::XSLStyleSheet::isLoading):
+ (WebCore::XSLStyleSheet::clearDocuments):
+ (WebCore::XSLStyleSheet::locateStylesheetSubResource):
+ * xml/XSLTProcessorLibxslt.cpp:
+ (WebCore::xsltParamArrayFromParameterMap):
+
2015-05-19 Jon Lee <[email protected]>
Improve text rendering of placeholder
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -405,12 +405,12 @@
String XMLHttpRequest::uppercaseKnownHTTPMethod(const String& method)
{
const char* const methods[] = { "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT" };
- for (unsigned i = 0; i < WTF_ARRAY_LENGTH(methods); ++i) {
- if (equalIgnoringCase(method, methods[i])) {
+ for (auto* value : methods) {
+ if (equalIgnoringCase(method, value)) {
// Don't bother allocating a new string if it's already all uppercase.
- if (method == methods[i])
+ if (method == value)
break;
- return ASCIILiteral(methods[i]);
+ return ASCIILiteral(value);
}
}
return method;
Modified: trunk/Source/WebCore/xml/XPathExpressionNode.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XPathExpressionNode.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XPathExpressionNode.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -50,10 +50,10 @@
{
ASSERT(m_subexpressions.isEmpty());
m_subexpressions = WTF::move(subexpressions);
- for (unsigned i = 0; i < m_subexpressions.size(); ++i) {
- m_isContextNodeSensitive |= m_subexpressions[i]->m_isContextNodeSensitive;
- m_isContextPositionSensitive |= m_subexpressions[i]->m_isContextPositionSensitive;
- m_isContextSizeSensitive |= m_subexpressions[i]->m_isContextSizeSensitive;
+ for (auto& subexpression : m_subexpressions) {
+ m_isContextNodeSensitive |= subexpression->m_isContextNodeSensitive;
+ m_isContextPositionSensitive |= subexpression->m_isContextPositionSensitive;
+ m_isContextSizeSensitive |= subexpression->m_isContextSizeSensitive;
}
}
Modified: trunk/Source/WebCore/xml/XPathFunctions.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XPathFunctions.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XPathFunctions.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -634,8 +634,8 @@
// To be really compliant, we should sort the node-set, as floating point addition is not associative.
// However, this is unlikely to ever become a practical issue, and sorting is slow.
- for (unsigned i = 0; i < nodes.size(); i++)
- sum += Value(stringValue(nodes[i])).toNumber();
+ for (auto& node : nodes)
+ sum += Value(stringValue(node.get())).toNumber();
return sum;
}
@@ -708,8 +708,8 @@
{ "true", { createFunctionTrue, 0 } },
};
- for (size_t i = 0; i < WTF_ARRAY_LENGTH(functions); ++i)
- functionMap.add(functions[i].name, functions[i].function);
+ for (auto& function : functions)
+ functionMap.add(function.name, function.function);
}
std::unique_ptr<Function> Function::create(const String& name, unsigned numArguments)
Modified: trunk/Source/WebCore/xml/XPathNodeSet.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XPathNodeSet.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XPathNodeSet.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -197,9 +197,8 @@
unsigned nodeCount = m_nodes.size();
ASSERT(nodeCount > 1);
- for (unsigned i = 0; i < nodeCount; ++i) {
- Node* node = m_nodes[i].get();
- nodes.add(node);
+ for (auto& node : m_nodes) {
+ nodes.add(node.get());
if (node->isAttributeNode())
containsAttributeNodes = true;
}
Modified: trunk/Source/WebCore/xml/XPathParser.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XPathParser.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XPathParser.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -99,8 +99,8 @@
{ "preceding-sibling", Step::PrecedingSiblingAxis },
{ "self", Step::SelfAxis }
};
- for (unsigned i = 0; i < WTF_ARRAY_LENGTH(axisNameList); ++i)
- axisNames.add(axisNameList[i].name, axisNameList[i].axis);
+ for (auto& axisName : axisNameList)
+ axisNames.add(axisName.name, axisName.axis);
}
static bool parseAxisName(const String& name, Step::Axis& type)
Modified: trunk/Source/WebCore/xml/XPathPath.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XPathPath.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XPathPath.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -51,18 +51,16 @@
nodes.sort();
EvaluationContext& evaluationContext = _expression_::evaluationContext();
- for (unsigned i = 0; i < m_predicates.size(); i++) {
+ for (auto& predicate : m_predicates) {
NodeSet newNodes;
evaluationContext.size = nodes.size();
evaluationContext.position = 0;
- for (unsigned j = 0; j < nodes.size(); j++) {
- Node* node = nodes[j];
-
+ for (auto& node : nodes) {
evaluationContext.node = node;
++evaluationContext.position;
- if (evaluatePredicate(*m_predicates[i]))
+ if (evaluatePredicate(*predicate))
newNodes.append(node);
}
nodes = WTF::move(newNodes);
@@ -109,32 +107,30 @@
{
bool resultIsSorted = nodes.isSorted();
- for (unsigned i = 0; i < m_steps.size(); i++) {
- Step& step = *m_steps[i];
+ for (auto& step : m_steps) {
NodeSet newNodes;
HashSet<Node*> newNodesSet;
- bool needToCheckForDuplicateNodes = !nodes.subtreesAreDisjoint() || (step.axis() != Step::ChildAxis && step.axis() != Step::SelfAxis
- && step.axis() != Step::DescendantAxis && step.axis() != Step::DescendantOrSelfAxis && step.axis() != Step::AttributeAxis);
+ bool needToCheckForDuplicateNodes = !nodes.subtreesAreDisjoint() || (step->axis() != Step::ChildAxis && step->axis() != Step::SelfAxis
+ && step->axis() != Step::DescendantAxis && step->axis() != Step::DescendantOrSelfAxis && step->axis() != Step::AttributeAxis);
if (needToCheckForDuplicateNodes)
resultIsSorted = false;
// This is a simplified check that can be improved to handle more cases.
- if (nodes.subtreesAreDisjoint() && (step.axis() == Step::ChildAxis || step.axis() == Step::SelfAxis))
+ if (nodes.subtreesAreDisjoint() && (step->axis() == Step::ChildAxis || step->axis() == Step::SelfAxis))
newNodes.markSubtreesDisjoint(true);
- for (unsigned j = 0; j < nodes.size(); j++) {
+ for (auto& node : nodes) {
NodeSet matches;
- step.evaluate(*nodes[j], matches);
+ step->evaluate(*node, matches);
if (!matches.isSorted())
resultIsSorted = false;
- for (size_t nodeIndex = 0; nodeIndex < matches.size(); ++nodeIndex) {
- Node* node = matches[nodeIndex];
- if (!needToCheckForDuplicateNodes || newNodesSet.add(node).isNewEntry)
- newNodes.append(node);
+ for (auto& match : matches) {
+ if (!needToCheckForDuplicateNodes || newNodesSet.add(match.get()).isNewEntry)
+ newNodes.append(match);
}
}
Modified: trunk/Source/WebCore/xml/XPathPredicate.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XPathPredicate.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XPathPredicate.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -111,28 +111,32 @@
// there is a node in the first node-set and a node in the second node-set such that the result of
// performing the comparison on the string-values of the two nodes is true.
const NodeSet& rhsSet = rhs.toNodeSet();
- for (unsigned lindex = 0; lindex < lhsSet.size(); ++lindex)
- for (unsigned rindex = 0; rindex < rhsSet.size(); ++rindex)
- if (compare(stringValue(lhsSet[lindex]), stringValue(rhsSet[rindex])))
+ for (auto& lhs : lhsSet) {
+ for (auto& rhs : rhsSet) {
+ if (compare(stringValue(lhs.get()), stringValue(rhs.get())))
return true;
+ }
+ }
return false;
}
if (rhs.isNumber()) {
// If one object to be compared is a node-set and the other is a number, then the comparison will be true
// if and only if there is a node in the node-set such that the result of performing the comparison on the number
// to be compared and on the result of converting the string-value of that node to a number using the number function is true.
- for (unsigned lindex = 0; lindex < lhsSet.size(); ++lindex)
- if (compare(Value(stringValue(lhsSet[lindex])).toNumber(), rhs))
+ for (auto& lhs : lhsSet) {
+ if (compare(Value(stringValue(lhs.get())).toNumber(), rhs))
return true;
+ }
return false;
}
if (rhs.isString()) {
// If one object to be compared is a node-set and the other is a string, then the comparison will be true
// if and only if there is a node in the node-set such that the result of performing the comparison on
// the string-value of the node and the other string is true.
- for (unsigned lindex = 0; lindex < lhsSet.size(); ++lindex)
- if (compare(stringValue(lhsSet[lindex]), rhs))
+ for (auto& lhs : lhsSet) {
+ if (compare(stringValue(lhs.get()), rhs))
return true;
+ }
return false;
}
if (rhs.isBoolean()) {
@@ -146,15 +150,17 @@
if (rhs.isNodeSet()) {
const NodeSet& rhsSet = rhs.toNodeSet();
if (lhs.isNumber()) {
- for (unsigned rindex = 0; rindex < rhsSet.size(); ++rindex)
- if (compare(lhs, Value(stringValue(rhsSet[rindex])).toNumber()))
+ for (auto& rhs : rhsSet) {
+ if (compare(lhs, Value(stringValue(rhs.get())).toNumber()))
return true;
+ }
return false;
}
if (lhs.isString()) {
- for (unsigned rindex = 0; rindex < rhsSet.size(); ++rindex)
- if (compare(lhs, stringValue(rhsSet[rindex])))
+ for (auto& rhs : rhsSet) {
+ if (compare(lhs, stringValue(rhs.get())))
return true;
+ }
return false;
}
if (lhs.isBoolean())
@@ -236,13 +242,12 @@
const NodeSet& rhsNodes = rhs.toNodeSet();
HashSet<Node*> nodes;
- for (size_t i = 0; i < resultSet.size(); ++i)
- nodes.add(resultSet[i]);
+ for (auto& result : resultSet)
+ nodes.add(result.get());
- for (size_t i = 0; i < rhsNodes.size(); ++i) {
- Node* node = rhsNodes[i];
- if (nodes.add(node).isNewEntry)
- resultSet.append(node);
+ for (auto& node : rhsNodes) {
+ if (nodes.add(node.get()).isNewEntry)
+ resultSet.append(node.get());
}
// It would also be possible to perform a merge sort here to avoid making an unsorted result,
Modified: trunk/Source/WebCore/xml/XPathStep.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XPathStep.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XPathStep.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -63,8 +63,7 @@
// E.g., there is no need to build a set of all "foo" nodes to evaluate "foo[@bar]", we can check the predicate while enumerating.
// This optimization can be applied to predicates that are not context node list sensitive, or to first predicate that is only context position sensitive, e.g. foo[position() mod 2 = 0].
Vector<std::unique_ptr<_expression_>> remainingPredicates;
- for (size_t i = 0; i < m_predicates.size(); ++i) {
- auto& predicate = m_predicates[i];
+ for (auto& predicate : m_predicates) {
if ((!predicateIsContextPositionSensitive(*predicate) || m_nodeTest.m_mergedPredicates.isEmpty()) && !predicate->isContextSizeSensitive() && remainingPredicates.isEmpty())
m_nodeTest.m_mergedPredicates.append(WTF::move(predicate));
else
@@ -108,15 +107,13 @@
bool Step::predicatesAreContextListInsensitive() const
{
- for (size_t i = 0; i < m_predicates.size(); ++i) {
- auto& predicate = *m_predicates[i];
- if (predicateIsContextPositionSensitive(predicate) || predicate.isContextSizeSensitive())
+ for (auto& predicate : m_predicates) {
+ if (predicateIsContextPositionSensitive(*predicate) || predicate->isContextSizeSensitive())
return false;
}
- for (size_t i = 0; i < m_nodeTest.m_mergedPredicates.size(); ++i) {
- auto& predicate = *m_nodeTest.m_mergedPredicates[i];
- if (predicateIsContextPositionSensitive(predicate) || predicate.isContextSizeSensitive())
+ for (auto& predicate : m_nodeTest.m_mergedPredicates) {
+ if (predicateIsContextPositionSensitive(*predicate) || predicate->isContextSizeSensitive())
return false;
}
@@ -131,9 +128,7 @@
nodesInAxis(context, nodes);
// Check predicates that couldn't be merged into node test.
- for (unsigned i = 0; i < m_predicates.size(); i++) {
- auto& predicate = *m_predicates[i];
-
+ for (auto& predicate : m_predicates) {
NodeSet newNodes;
if (!nodes.isSorted())
newNodes.markSorted(false);
@@ -144,7 +139,7 @@
evaluationContext.node = node;
evaluationContext.size = nodes.size();
evaluationContext.position = j + 1;
- if (evaluatePredicate(predicate))
+ if (evaluatePredicate(*predicate))
newNodes.append(node);
}
@@ -233,11 +228,10 @@
// Only the first merged predicate may depend on position.
++evaluationContext.position;
- auto& mergedPredicates = nodeTest.m_mergedPredicates;
- for (unsigned i = 0; i < mergedPredicates.size(); i++) {
+ for (auto& predicate : nodeTest.m_mergedPredicates) {
// No need to set context size - we only get here when evaluating predicates that do not depend on it.
evaluationContext.node = &node;
- if (!evaluatePredicate(*mergedPredicates[i]))
+ if (!evaluatePredicate(*predicate))
return false;
}
Modified: trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -82,16 +82,16 @@
if (!m_stylesheetDocTaken)
xmlFreeDoc(m_stylesheetDoc);
- for (unsigned i = 0; i < m_children.size(); ++i) {
- ASSERT(m_children.at(i)->parentStyleSheet() == this);
- m_children.at(i)->setParentStyleSheet(0);
+ for (auto& child : m_children) {
+ ASSERT(child->parentStyleSheet() == this);
+ child->setParentStyleSheet(0);
}
}
bool XSLStyleSheet::isLoading() const
{
- for (unsigned i = 0; i < m_children.size(); ++i) {
- if (m_children.at(i)->isLoading())
+ for (auto& child : m_children) {
+ if (child->isLoading())
return true;
}
return false;
@@ -117,8 +117,7 @@
void XSLStyleSheet::clearDocuments()
{
m_stylesheetDoc = 0;
- for (unsigned i = 0; i < m_children.size(); ++i) {
- XSLImportRule* import = m_children.at(i).get();
+ for (auto& import : m_children) {
if (import->styleSheet())
import->styleSheet()->clearDocuments();
}
@@ -273,8 +272,7 @@
xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri)
{
bool matchedParent = (parentDoc == document());
- for (unsigned i = 0; i < m_children.size(); ++i) {
- XSLImportRule* import = m_children.at(i).get();
+ for (auto& import : m_children) {
XSLStyleSheet* child = import->styleSheet();
if (!child)
continue;
Modified: trunk/Source/WebCore/xml/XSLTProcessorLibxslt.cpp (184565 => 184566)
--- trunk/Source/WebCore/xml/XSLTProcessorLibxslt.cpp 2015-05-19 16:26:04 UTC (rev 184565)
+++ trunk/Source/WebCore/xml/XSLTProcessorLibxslt.cpp 2015-05-19 16:29:37 UTC (rev 184566)
@@ -226,11 +226,10 @@
const char** parameterArray = (const char**)fastMalloc(((parameters.size() * 2) + 1) * sizeof(char*));
- XSLTProcessor::ParameterMap::iterator end = parameters.end();
unsigned index = 0;
- for (XSLTProcessor::ParameterMap::iterator it = parameters.begin(); it != end; ++it) {
- parameterArray[index++] = fastStrDup(it->key.utf8().data());
- parameterArray[index++] = fastStrDup(it->value.utf8().data());
+ for (auto& parameter : parameters) {
+ parameterArray[index++] = fastStrDup(parameter.key.utf8().data());
+ parameterArray[index++] = fastStrDup(parameter.value.utf8().data());
}
parameterArray[index] = 0;