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

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_slice.h

Issue 16256014: IndexedDB: Convert decoding functions to pass StringPieces vs. pointers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correct bogus iterator dereference in unit test Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_
6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_piece.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 class LevelDBSlice { 15 class LevelDBSlice {
15 public: 16 public:
16 LevelDBSlice(const char* begin, const char* end) : begin_(begin), end_(end) { 17 LevelDBSlice(const char* begin, const char* end) : begin_(begin), end_(end) {
17 DCHECK_GE(end_, begin_); 18 DCHECK_GE(end_, begin_);
18 } 19 }
19 20
20 explicit LevelDBSlice(const std::vector<char>& v) 21 explicit LevelDBSlice(const std::vector<char>& v)
21 : begin_(v.empty() ? NULL : &*v.begin()), end_(begin_ + v.size()) { 22 : begin_(v.empty() ? NULL : &*v.begin()), end_(begin_ + v.size()) {
22 DCHECK_GE(end_, begin_); 23 DCHECK_GE(end_, begin_);
23 } 24 }
24 25
26 explicit LevelDBSlice(const std::string& v)
27 : begin_(v.data()), end_(v.data() + v.size()) {
28 DCHECK_GE(end_, begin_);
29 }
30
25 ~LevelDBSlice() {} 31 ~LevelDBSlice() {}
26 32
27 const char* begin() const { return begin_; } 33 const char* begin() const { return begin_; }
28 const char* end() const { return end_; } 34 const char* end() const { return end_; }
29 35
36 base::StringPiece AsStringPiece() const {
37 return base::StringPiece(begin_, end_ - begin_);
38 }
39
30 private: 40 private:
31 const char* begin_; 41 const char* begin_;
32 const char* end_; 42 const char* end_;
33 }; 43 };
34 44
35 } // namespace content 45 } // namespace content
36 46
37 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_ 47 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_database.cc ('k') | content/browser/indexed_db/leveldb/leveldb_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698