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

Side by Side Diff: components/leveldb/public/cpp/util.cc

Issue 2285623002: [Leveldb] Use std::{string,vector} instead of mojo::{String,Array}. (Closed)
Patch Set: Address comments from Yuzhu Created 4 years, 3 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
« no previous file with comments | « components/leveldb/public/cpp/util.h ('k') | components/leveldb/public/interfaces/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/leveldb/public/cpp/util.h" 5 #include "components/leveldb/public/cpp/util.h"
6 6
7 #include "third_party/leveldatabase/src/include/leveldb/status.h" 7 #include "third_party/leveldatabase/src/include/leveldb/status.h"
8 8
9 namespace leveldb { 9 namespace leveldb {
10 10
(...skipping 27 matching lines...) Expand all
38 return leveldb::Status::InvalidArgument(msg, msg2); 38 return leveldb::Status::InvalidArgument(msg, msg2);
39 case mojom::DatabaseError::IO_ERROR: 39 case mojom::DatabaseError::IO_ERROR:
40 return leveldb::Status::IOError(msg, msg2); 40 return leveldb::Status::IOError(msg, msg2);
41 } 41 }
42 42
43 // This will never be reached, but we still have configurations which don't 43 // This will never be reached, but we still have configurations which don't
44 // do switch enum checking. 44 // do switch enum checking.
45 return leveldb::Status::InvalidArgument(msg, msg2); 45 return leveldb::Status::InvalidArgument(msg, msg2);
46 } 46 }
47 47
48 leveldb::Slice GetSliceFor(const mojo::Array<uint8_t>& key) { 48 leveldb::Slice GetSliceFor(const std::vector<uint8_t>& key) {
49 if (key.size() == 0) 49 if (key.size() == 0)
50 return leveldb::Slice(); 50 return leveldb::Slice();
51 return leveldb::Slice(reinterpret_cast<const char*>(&key.front()), 51 return leveldb::Slice(reinterpret_cast<const char*>(&key.front()),
52 key.size()); 52 key.size());
53 } 53 }
54 54
55 mojo::Array<uint8_t> GetArrayFor(const leveldb::Slice& s) { 55 std::vector<uint8_t> GetVectorFor(const leveldb::Slice& s) {
56 if (s.size() == 0) 56 if (s.size() == 0)
57 return mojo::Array<uint8_t>(); 57 return std::vector<uint8_t>();
58 return mojo::Array<uint8_t>(std::vector<uint8_t>( 58 return std::vector<uint8_t>(
59 reinterpret_cast<const uint8_t*>(s.data()), 59 reinterpret_cast<const uint8_t*>(s.data()),
60 reinterpret_cast<const uint8_t*>(s.data() + s.size()))); 60 reinterpret_cast<const uint8_t*>(s.data() + s.size()));
61 }
62
63 std::string Uint8VectorToStdString(const std::vector<uint8_t>& input) {
64 return std::string(reinterpret_cast<const char*>(input.data()), input.size());
65 }
66
67 std::vector<uint8_t> StdStringToUint8Vector(const std::string& input) {
68 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data());
69 return std::vector<uint8_t>(data, data + input.size());
61 } 70 }
62 71
63 } // namespace leveldb 72 } // namespace leveldb
OLDNEW
« no previous file with comments | « components/leveldb/public/cpp/util.h ('k') | components/leveldb/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698