Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/indexed_db/indexed_db_key.h" | 5 #include "content/common/indexed_db/indexed_db_key.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 return type_ > other.type_ ? -1 : 1; | 114 return type_ > other.type_ ? -1 : 1; |
| 115 | 115 |
| 116 switch (type_) { | 116 switch (type_) { |
| 117 case WebIDBKeyTypeArray: | 117 case WebIDBKeyTypeArray: |
| 118 for (size_t i = 0; i < array_.size() && i < other.array_.size(); ++i) { | 118 for (size_t i = 0; i < array_.size() && i < other.array_.size(); ++i) { |
| 119 if (int result = array_[i].Compare(other.array_[i])) | 119 if (int result = array_[i].Compare(other.array_[i])) |
| 120 return result; | 120 return result; |
| 121 } | 121 } |
| 122 if (array_.size() < other.array_.size()) | 122 if (array_.size() < other.array_.size()) |
| 123 return -1; | 123 return -1; |
| 124 if (array_.size() > other.array_.size()) | 124 return (array_.size() > other.array_.size()) ? 1 : 0; |
|
Peter Kasting
2014/03/18 02:55:54
(Was trying for a consistent style in this switch
| |
| 125 return 1; | 125 |
| 126 return 0; | |
| 127 case WebIDBKeyTypeBinary: | 126 case WebIDBKeyTypeBinary: |
| 128 return binary_.compare(other.binary_); | 127 return binary_.compare(other.binary_); |
| 128 | |
| 129 case WebIDBKeyTypeString: | 129 case WebIDBKeyTypeString: |
| 130 return string_.compare(other.string_); | 130 return string_.compare(other.string_); |
| 131 | |
| 131 case WebIDBKeyTypeDate: | 132 case WebIDBKeyTypeDate: |
| 132 return (date_ < other.date_) ? -1 : (date_ > other.date_) ? 1 : 0; | 133 if (date_ < other.date_) |
| 134 return -1; | |
| 135 return (date_ > other.date_) ? 1 : 0; | |
| 136 | |
| 133 case WebIDBKeyTypeNumber: | 137 case WebIDBKeyTypeNumber: |
| 134 return (number_ < other.number_) ? -1 : (number_ > other.number_) ? 1 : 0; | 138 if (number_ < other.number_) |
| 139 return -1; | |
| 140 return (number_ > other.number_) ? 1 : 0; | |
| 141 | |
| 135 case WebIDBKeyTypeInvalid: | 142 case WebIDBKeyTypeInvalid: |
| 136 case WebIDBKeyTypeNull: | 143 case WebIDBKeyTypeNull: |
| 137 case WebIDBKeyTypeMin: | 144 case WebIDBKeyTypeMin: |
| 138 default: | 145 default: |
| 139 NOTREACHED(); | 146 NOTREACHED(); |
| 140 return 0; | 147 return 0; |
| 141 } | 148 } |
| 142 NOTREACHED(); | |
| 143 return 0; | |
| 144 } | 149 } |
| 145 | 150 |
| 146 bool IndexedDBKey::IsLessThan(const IndexedDBKey& other) const { | 151 bool IndexedDBKey::IsLessThan(const IndexedDBKey& other) const { |
| 147 return Compare(other) < 0; | 152 return Compare(other) < 0; |
| 148 } | 153 } |
| 149 | 154 |
| 150 bool IndexedDBKey::IsEqual(const IndexedDBKey& other) const { | 155 bool IndexedDBKey::IsEqual(const IndexedDBKey& other) const { |
| 151 return !Compare(other); | 156 return !Compare(other); |
| 152 } | 157 } |
| 153 | 158 |
| 154 bool IndexedDBKey::IsValid() const { | 159 bool IndexedDBKey::IsValid() const { |
| 155 if (type_ == WebIDBKeyTypeInvalid || type_ == WebIDBKeyTypeNull) | 160 if (type_ == WebIDBKeyTypeInvalid || type_ == WebIDBKeyTypeNull) |
| 156 return false; | 161 return false; |
| 157 | 162 |
| 158 if (type_ == WebIDBKeyTypeArray) { | 163 if (type_ == WebIDBKeyTypeArray) { |
| 159 for (size_t i = 0; i < array_.size(); i++) { | 164 for (size_t i = 0; i < array_.size(); i++) { |
| 160 if (!array_[i].IsValid()) | 165 if (!array_[i].IsValid()) |
| 161 return false; | 166 return false; |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 | 169 |
| 165 return true; | 170 return true; |
| 166 } | 171 } |
| 167 | 172 |
| 168 } // namespace content | 173 } // namespace content |
| OLD | NEW |