| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2005 Frerich Raabe <raabe@kde.org> | 2 * Copyright 2005 Frerich Raabe <raabe@kde.org> |
| 3 * Copyright (C) 2006 Apple Computer, Inc. | 3 * Copyright (C) 2006 Apple Computer, Inc. |
| 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 const Value& rhs) const { | 103 const Value& rhs) const { |
| 104 if (lhs.isNodeSet()) { | 104 if (lhs.isNodeSet()) { |
| 105 const NodeSet& lhsSet = lhs.toNodeSet(&context); | 105 const NodeSet& lhsSet = lhs.toNodeSet(&context); |
| 106 if (rhs.isNodeSet()) { | 106 if (rhs.isNodeSet()) { |
| 107 // If both objects to be compared are node-sets, then the comparison | 107 // If both objects to be compared are node-sets, then the comparison |
| 108 // will be true if and only if there is a node in the first node-set | 108 // will be true if and only if there is a node in the first node-set |
| 109 // and a node in the second node-set such that the result of | 109 // and a node in the second node-set such that the result of |
| 110 // performing the comparison on the string-values of the two nodes | 110 // performing the comparison on the string-values of the two nodes |
| 111 // is true. | 111 // is true. |
| 112 const NodeSet& rhsSet = rhs.toNodeSet(&context); | 112 const NodeSet& rhsSet = rhs.toNodeSet(&context); |
| 113 for (unsigned lindex = 0; lindex < lhsSet.size(); ++lindex) { | 113 for (const auto& leftNode : lhsSet) { |
| 114 for (unsigned rindex = 0; rindex < rhsSet.size(); ++rindex) { | 114 for (const auto& rightNode : rhsSet) { |
| 115 if (compare(context, stringValue(lhsSet[lindex]), | 115 if (compare(context, stringValue(leftNode), stringValue(rightNode))) |
| 116 stringValue(rhsSet[rindex]))) | |
| 117 return true; | 116 return true; |
| 118 } | 117 } |
| 119 } | 118 } |
| 120 return false; | 119 return false; |
| 121 } | 120 } |
| 122 if (rhs.isNumber()) { | 121 if (rhs.isNumber()) { |
| 123 // If one object to be compared is a node-set and the other is a | 122 // If one object to be compared is a node-set and the other is a |
| 124 // number, then the comparison will be true if and only if there is | 123 // number, then the comparison will be true if and only if there is |
| 125 // a node in the node-set such that the result of performing the | 124 // a node in the node-set such that the result of performing the |
| 126 // comparison on the number to be compared and on the result of | 125 // comparison on the number to be compared and on the result of |
| 127 // converting the string-value of that node to a number using the | 126 // converting the string-value of that node to a number using the |
| 128 // number function is true. | 127 // number function is true. |
| 129 for (unsigned lindex = 0; lindex < lhsSet.size(); ++lindex) { | 128 for (const auto& leftNode : lhsSet) { |
| 130 if (compare(context, Value(stringValue(lhsSet[lindex])).toNumber(), | 129 if (compare(context, Value(stringValue(leftNode)).toNumber(), rhs)) |
| 131 rhs)) | |
| 132 return true; | 130 return true; |
| 133 } | 131 } |
| 134 return false; | 132 return false; |
| 135 } | 133 } |
| 136 if (rhs.isString()) { | 134 if (rhs.isString()) { |
| 137 // If one object to be compared is a node-set and the other is a | 135 // If one object to be compared is a node-set and the other is a |
| 138 // string, then the comparison will be true if and only if there is | 136 // string, then the comparison will be true if and only if there is |
| 139 // a node in the node-set such that the result of performing the | 137 // a node in the node-set such that the result of performing the |
| 140 // comparison on the string-value of the node and the other string | 138 // comparison on the string-value of the node and the other string |
| 141 // is true. | 139 // is true. |
| 142 for (unsigned lindex = 0; lindex < lhsSet.size(); ++lindex) { | 140 for (const auto& leftNode : lhsSet) { |
| 143 if (compare(context, stringValue(lhsSet[lindex]), rhs)) | 141 if (compare(context, stringValue(leftNode), rhs)) |
| 144 return true; | 142 return true; |
| 145 } | 143 } |
| 146 return false; | 144 return false; |
| 147 } | 145 } |
| 148 if (rhs.isBoolean()) { | 146 if (rhs.isBoolean()) { |
| 149 // If one object to be compared is a node-set and the other is a | 147 // If one object to be compared is a node-set and the other is a |
| 150 // boolean, then the comparison will be true if and only if the | 148 // boolean, then the comparison will be true if and only if the |
| 151 // result of performing the comparison on the boolean and on the | 149 // result of performing the comparison on the boolean and on the |
| 152 // result of converting the node-set to a boolean using the boolean | 150 // result of converting the node-set to a boolean using the boolean |
| 153 // function is true. | 151 // function is true. |
| 154 return compare(context, lhs.toBoolean(), rhs); | 152 return compare(context, lhs.toBoolean(), rhs); |
| 155 } | 153 } |
| 156 NOTREACHED(); | 154 NOTREACHED(); |
| 157 } | 155 } |
| 158 if (rhs.isNodeSet()) { | 156 if (rhs.isNodeSet()) { |
| 159 const NodeSet& rhsSet = rhs.toNodeSet(&context); | 157 const NodeSet& rhsSet = rhs.toNodeSet(&context); |
| 160 if (lhs.isNumber()) { | 158 if (lhs.isNumber()) { |
| 161 for (unsigned rindex = 0; rindex < rhsSet.size(); ++rindex) { | 159 for (const auto& rightNode : rhsSet) { |
| 162 if (compare(context, lhs, | 160 if (compare(context, lhs, Value(stringValue(rightNode)).toNumber())) |
| 163 Value(stringValue(rhsSet[rindex])).toNumber())) | |
| 164 return true; | 161 return true; |
| 165 } | 162 } |
| 166 return false; | 163 return false; |
| 167 } | 164 } |
| 168 if (lhs.isString()) { | 165 if (lhs.isString()) { |
| 169 for (unsigned rindex = 0; rindex < rhsSet.size(); ++rindex) { | 166 for (const auto& rightNode : rhsSet) { |
| 170 if (compare(context, lhs, stringValue(rhsSet[rindex]))) | 167 if (compare(context, lhs, stringValue(rightNode))) |
| 171 return true; | 168 return true; |
| 172 } | 169 } |
| 173 return false; | 170 return false; |
| 174 } | 171 } |
| 175 if (lhs.isBoolean()) | 172 if (lhs.isBoolean()) |
| 176 return compare(context, lhs, rhs.toBoolean()); | 173 return compare(context, lhs, rhs.toBoolean()); |
| 177 NOTREACHED(); | 174 NOTREACHED(); |
| 178 } | 175 } |
| 179 | 176 |
| 180 // Neither side is a NodeSet. | 177 // Neither side is a NodeSet. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 232 } |
| 236 | 233 |
| 237 Value Union::evaluate(EvaluationContext& context) const { | 234 Value Union::evaluate(EvaluationContext& context) const { |
| 238 Value lhsResult = subExpr(0)->evaluate(context); | 235 Value lhsResult = subExpr(0)->evaluate(context); |
| 239 Value rhs = subExpr(1)->evaluate(context); | 236 Value rhs = subExpr(1)->evaluate(context); |
| 240 | 237 |
| 241 NodeSet& resultSet = lhsResult.modifiableNodeSet(context); | 238 NodeSet& resultSet = lhsResult.modifiableNodeSet(context); |
| 242 const NodeSet& rhsNodes = rhs.toNodeSet(&context); | 239 const NodeSet& rhsNodes = rhs.toNodeSet(&context); |
| 243 | 240 |
| 244 HeapHashSet<Member<Node>> nodes; | 241 HeapHashSet<Member<Node>> nodes; |
| 245 for (size_t i = 0; i < resultSet.size(); ++i) | 242 for (const auto& node : resultSet) |
| 246 nodes.add(resultSet[i]); | 243 nodes.add(node); |
| 247 | 244 |
| 248 for (size_t i = 0; i < rhsNodes.size(); ++i) { | 245 for (const auto& node : rhsNodes) { |
| 249 Node* node = rhsNodes[i]; | |
| 250 if (nodes.add(node).isNewEntry) | 246 if (nodes.add(node).isNewEntry) |
| 251 resultSet.append(node); | 247 resultSet.append(node); |
| 252 } | 248 } |
| 253 | 249 |
| 254 // It is also possible to use merge sort to avoid making the result | 250 // It is also possible to use merge sort to avoid making the result |
| 255 // unsorted; but this would waste the time in cases when order is not | 251 // unsorted; but this would waste the time in cases when order is not |
| 256 // important. | 252 // important. |
| 257 resultSet.markSorted(false); | 253 resultSet.markSorted(false); |
| 258 return lhsResult; | 254 return lhsResult; |
| 259 } | 255 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 275 new Number(result.toNumber())) | 271 new Number(result.toNumber())) |
| 276 .evaluate(context) | 272 .evaluate(context) |
| 277 .toBoolean(); | 273 .toBoolean(); |
| 278 | 274 |
| 279 return result.toBoolean(); | 275 return result.toBoolean(); |
| 280 } | 276 } |
| 281 | 277 |
| 282 } // namespace XPath | 278 } // namespace XPath |
| 283 | 279 |
| 284 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |