Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: content/common/indexed_db/indexed_db_key.cc

Issue 9104026: Iterate an array in O(n) rather than O(n^2) time during IDBKey conversion. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
10 10
11 using WebKit::WebIDBKey; 11 using WebKit::WebIDBKey;
12 using WebKit::WebVector;
12 13
13 IndexedDBKey::IndexedDBKey() 14 IndexedDBKey::IndexedDBKey()
14 : type_(WebIDBKey::NullType), 15 : type_(WebIDBKey::NullType),
15 date_(0), 16 date_(0),
16 number_(0) { 17 number_(0) {
17 } 18 }
18 19
19 IndexedDBKey::IndexedDBKey(const WebIDBKey& key) { 20 IndexedDBKey::IndexedDBKey(const WebIDBKey& key) {
20 Set(key); 21 Set(key);
21 } 22 }
(...skipping 26 matching lines...) Expand all
48 49
49 void IndexedDBKey::SetNumber(double number) { 50 void IndexedDBKey::SetNumber(double number) {
50 type_ = WebIDBKey::NumberType; 51 type_ = WebIDBKey::NumberType;
51 number_ = number; 52 number_ = number;
52 } 53 }
53 54
54 void IndexedDBKey::Set(const WebIDBKey& key) { 55 void IndexedDBKey::Set(const WebIDBKey& key) {
55 type_ = key.type(); 56 type_ = key.type();
56 array_.clear(); 57 array_.clear();
57 if (key.type() == WebIDBKey::ArrayType) { 58 if (key.type() == WebIDBKey::ArrayType) {
58 for (size_t i = 0; i < key.array().size(); ++i) { 59 WebVector<WebIDBKey> array = key.array();
59 array_.push_back(IndexedDBKey(key.array()[i])); 60 for (size_t i = 0; i < array.size(); ++i) {
61 array_.push_back(IndexedDBKey(array[i]));
60 } 62 }
61 } 63 }
62 string_ = key.type() == WebIDBKey::StringType ? 64 string_ = key.type() == WebIDBKey::StringType ?
63 static_cast<string16>(key.string()) : string16(); 65 static_cast<string16>(key.string()) : string16();
64 number_ = key.type() == WebIDBKey::NumberType ? key.number() : 0; 66 number_ = key.type() == WebIDBKey::NumberType ? key.number() : 0;
65 date_ = key.type() == WebIDBKey::DateType ? key.date() : 0; 67 date_ = key.type() == WebIDBKey::DateType ? key.date() : 0;
66 } 68 }
67 69
68 IndexedDBKey::operator WebIDBKey() const { 70 IndexedDBKey::operator WebIDBKey() const {
69 switch (type_) { 71 switch (type_) {
70 case WebIDBKey::ArrayType: 72 case WebIDBKey::ArrayType:
71 return WebIDBKey::createArray(array_); 73 return WebIDBKey::createArray(array_);
72 case WebIDBKey::StringType: 74 case WebIDBKey::StringType:
73 return WebIDBKey::createString(string_); 75 return WebIDBKey::createString(string_);
74 case WebIDBKey::DateType: 76 case WebIDBKey::DateType:
75 return WebIDBKey::createDate(date_); 77 return WebIDBKey::createDate(date_);
76 case WebIDBKey::NumberType: 78 case WebIDBKey::NumberType:
77 return WebIDBKey::createNumber(number_); 79 return WebIDBKey::createNumber(number_);
78 case WebIDBKey::InvalidType: 80 case WebIDBKey::InvalidType:
79 return WebIDBKey::createInvalid(); 81 return WebIDBKey::createInvalid();
80 case WebIDBKey::NullType: 82 case WebIDBKey::NullType:
81 return WebIDBKey::createNull(); 83 return WebIDBKey::createNull();
82 } 84 }
83 NOTREACHED(); 85 NOTREACHED();
84 return WebIDBKey::createInvalid(); 86 return WebIDBKey::createInvalid();
85 } 87 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698