OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 template <typename T> | 53 template <typename T> |
54 static int CompareNumbers(const T& a, const T& b) { | 54 static int CompareNumbers(const T& a, const T& b) { |
55 if (a < b) | 55 if (a < b) |
56 return -1; | 56 return -1; |
57 if (b < a) | 57 if (b < a) |
58 return 1; | 58 return 1; |
59 return 0; | 59 return 0; |
60 } | 60 } |
61 | 61 |
62 int IDBKey::Compare(const IDBKey* other) const { | 62 int IDBKey::Compare(const IDBKey* other) const { |
63 ASSERT(other); | 63 DCHECK(other); |
64 if (type_ != other->type_) | 64 if (type_ != other->type_) |
65 return type_ > other->type_ ? -1 : 1; | 65 return type_ > other->type_ ? -1 : 1; |
66 | 66 |
67 switch (type_) { | 67 switch (type_) { |
68 case kArrayType: | 68 case kArrayType: |
69 for (size_t i = 0; i < array_.size() && i < other->array_.size(); ++i) { | 69 for (size_t i = 0; i < array_.size() && i < other->array_.size(); ++i) { |
70 if (int result = array_[i]->Compare(other->array_[i].Get())) | 70 if (int result = array_[i]->Compare(other->array_[i].Get())) |
71 return result; | 71 return result; |
72 } | 72 } |
73 return CompareNumbers(array_.size(), other->array_.size()); | 73 return CompareNumbers(array_.size(), other->array_.size()); |
74 case kBinaryType: | 74 case kBinaryType: |
75 if (int result = | 75 if (int result = |
76 memcmp(binary_->Data(), other->binary_->Data(), | 76 memcmp(binary_->Data(), other->binary_->Data(), |
77 std::min(binary_->size(), other->binary_->size()))) | 77 std::min(binary_->size(), other->binary_->size()))) |
78 return result < 0 ? -1 : 1; | 78 return result < 0 ? -1 : 1; |
79 return CompareNumbers(binary_->size(), other->binary_->size()); | 79 return CompareNumbers(binary_->size(), other->binary_->size()); |
80 case kStringType: | 80 case kStringType: |
81 return CodePointCompare(string_, other->string_); | 81 return CodePointCompare(string_, other->string_); |
82 case kDateType: | 82 case kDateType: |
83 case kNumberType: | 83 case kNumberType: |
84 return CompareNumbers(number_, other->number_); | 84 return CompareNumbers(number_, other->number_); |
85 case kInvalidType: | 85 case kInvalidType: |
86 case kTypeEnumMax: | 86 case kTypeEnumMax: |
87 ASSERT_NOT_REACHED(); | 87 NOTREACHED(); |
88 return 0; | 88 return 0; |
89 } | 89 } |
90 | 90 |
91 ASSERT_NOT_REACHED(); | 91 NOTREACHED(); |
92 return 0; | 92 return 0; |
93 } | 93 } |
94 | 94 |
95 bool IDBKey::IsLessThan(const IDBKey* other) const { | 95 bool IDBKey::IsLessThan(const IDBKey* other) const { |
96 ASSERT(other); | 96 DCHECK(other); |
97 return Compare(other) == -1; | 97 return Compare(other) == -1; |
98 } | 98 } |
99 | 99 |
100 bool IDBKey::IsEqual(const IDBKey* other) const { | 100 bool IDBKey::IsEqual(const IDBKey* other) const { |
101 if (!other) | 101 if (!other) |
102 return false; | 102 return false; |
103 | 103 |
104 return !Compare(other); | 104 return !Compare(other); |
105 } | 105 } |
106 | 106 |
(...skipping 10 matching lines...) Expand all Loading... |
117 [](const Member<IDBKey> a, const Member<IDBKey> b) { | 117 [](const Member<IDBKey> a, const Member<IDBKey> b) { |
118 return a->IsLessThan(b); | 118 return a->IsLessThan(b); |
119 }); | 119 }); |
120 const auto end = std::unique(result.begin(), result.end()); | 120 const auto end = std::unique(result.begin(), result.end()); |
121 DCHECK_LE(static_cast<size_t>(end - result.begin()), result.size()); | 121 DCHECK_LE(static_cast<size_t>(end - result.begin()), result.size()); |
122 result.Resize(end - result.begin()); | 122 result.Resize(end - result.begin()); |
123 return result; | 123 return result; |
124 } | 124 } |
125 | 125 |
126 } // namespace blink | 126 } // namespace blink |
OLD | NEW |