aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Local
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-01-27 17:53:27 -0500
committerGravatar Gil <mcg@google.com>2018-01-27 14:53:27 -0800
commitaf6976a907b0d2a9fadbb14d7258bab44f075364 (patch)
tree62918ca2d8da0696967e3003e495ba11cd56bf33 /Firestore/Source/Local
parent7226b4adf38e4732dfb9a840d25f86d3e5533bdb (diff)
normalize and port the rest of Firebase/Port code (#713)
* normalize bits * normalize ordered_code
Diffstat (limited to 'Firestore/Source/Local')
-rw-r--r--Firestore/Source/Local/FSTLevelDBKey.mm37
-rw-r--r--Firestore/Source/Local/FSTLevelDBMutationQueue.mm2
-rw-r--r--Firestore/Source/Local/FSTLevelDBQueryCache.mm3
-rw-r--r--Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm3
-rw-r--r--Firestore/Source/Local/FSTWriteGroup.mm3
-rw-r--r--Firestore/Source/Local/StringView.h12
6 files changed, 33 insertions, 27 deletions
diff --git a/Firestore/Source/Local/FSTLevelDBKey.mm b/Firestore/Source/Local/FSTLevelDBKey.mm
index 074d5c5..9850fff 100644
--- a/Firestore/Source/Local/FSTLevelDBKey.mm
+++ b/Firestore/Source/Local/FSTLevelDBKey.mm
@@ -18,13 +18,14 @@
#include <string>
-#include "Firestore/Port/ordered_code.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTPath.h"
+#include "Firestore/core/src/firebase/firestore/util/ordered_code.h"
+
NS_ASSUME_NONNULL_BEGIN
-using Firestore::OrderedCode;
+using firebase::firestore::util::OrderedCode;
using Firestore::StringView;
using leveldb::Slice;
@@ -109,11 +110,11 @@ void WriteComponentLabel(std::string *dest, FSTComponentLabel label) {
*/
BOOL ReadComponentLabel(leveldb::Slice *contents, FSTComponentLabel *label) {
int64_t rawResult = 0;
- Slice tmp = *contents;
+ absl::string_view tmp(contents->data(), contents->size());
if (OrderedCode::ReadSignedNumIncreasing(&tmp, &rawResult)) {
if (rawResult >= FSTComponentLabelTerminator && rawResult <= FSTComponentLabelUnknown) {
*label = static_cast<FSTComponentLabel>(rawResult);
- *contents = tmp;
+ *contents = leveldb::Slice(tmp.data(), tmp.size());
return YES;
}
}
@@ -128,9 +129,9 @@ BOOL ReadComponentLabel(leveldb::Slice *contents, FSTComponentLabel *label) {
*
* If the read is successful, returns YES and contents will be updated to the next unread byte.
*/
-BOOL ReadComponentLabelMatching(Slice *contents, FSTComponentLabel expectedLabel) {
+BOOL ReadComponentLabelMatching(absl::string_view *contents, FSTComponentLabel expectedLabel) {
int64_t rawResult = 0;
- Slice tmp = *contents;
+ absl::string_view tmp = *contents;
if (OrderedCode::ReadSignedNumIncreasing(&tmp, &rawResult)) {
if (rawResult == expectedLabel) {
*contents = tmp;
@@ -152,10 +153,10 @@ BOOL ReadComponentLabelMatching(Slice *contents, FSTComponentLabel expectedLabel
*/
BOOL ReadInt32(Slice *contents, int32_t *result) {
int64_t rawResult = 0;
- Slice tmp = *contents;
+ absl::string_view tmp(contents->data(), contents->size());
if (OrderedCode::ReadSignedNumIncreasing(&tmp, &rawResult)) {
if (rawResult >= INT32_MIN && rawResult <= INT32_MAX) {
- *contents = tmp;
+ *contents = leveldb::Slice(tmp.data(), tmp.size());
*result = static_cast<int32_t>(rawResult);
return YES;
}
@@ -180,10 +181,11 @@ void WriteLabeledInt32(std::string *dest, FSTComponentLabel label, int32_t value
* value will be set to the decoded integer value.
*/
BOOL ReadLabeledInt32(Slice *contents, FSTComponentLabel expectedLabel, int32_t *value) {
- Slice tmp = *contents;
+ absl::string_view tmp(contents->data(), contents->size());
if (ReadComponentLabelMatching(&tmp, expectedLabel)) {
- if (ReadInt32(&tmp, value)) {
- *contents = tmp;
+ Slice tmpSlice = leveldb::Slice(tmp.data(), tmp.size());
+ if (ReadInt32(&tmpSlice, value)) {
+ *contents = tmpSlice;
return YES;
}
}
@@ -207,10 +209,10 @@ void WriteLabeledString(std::string *dest, FSTComponentLabel label, StringView v
* value will be set to the decoded string value.
*/
BOOL ReadLabeledString(Slice *contents, FSTComponentLabel expectedLabel, std::string *value) {
- Slice tmp = *contents;
+ absl::string_view tmp(contents->data(), contents->size());
if (ReadComponentLabelMatching(&tmp, expectedLabel)) {
if (OrderedCode::ReadString(&tmp, value)) {
- *contents = tmp;
+ *contents = leveldb::Slice(tmp.data(), tmp.size());
return YES;
}
}
@@ -272,7 +274,7 @@ BOOL ReadDocumentKey(Slice *contents, FSTDocumentKey *__strong *result) {
for (;;) {
// Advance a temporary slice to avoid advancing contents into the next key component which may
// not be a path segment.
- Slice readPosition = completeSegments;
+ absl::string_view readPosition(completeSegments.data(), completeSegments.size());
if (!ReadComponentLabelMatching(&readPosition, FSTComponentLabelPathSegment)) {
break;
}
@@ -284,7 +286,7 @@ BOOL ReadDocumentKey(Slice *contents, FSTDocumentKey *__strong *result) {
[pathSegments addObject:pathSegment];
segment.clear();
- completeSegments = readPosition;
+ completeSegments = leveldb::Slice(readPosition.data(), readPosition.size());
}
FSTResourcePath *path = [FSTResourcePath pathWithSegments:pathSegments];
@@ -304,7 +306,10 @@ inline void WriteTerminator(std::string *dest) {
}
inline BOOL ReadTerminator(Slice *contents) {
- return ReadComponentLabelMatching(contents, FSTComponentLabelTerminator);
+ absl::string_view tmp(contents->data(), contents->size());
+ BOOL result = ReadComponentLabelMatching(&tmp, FSTComponentLabelTerminator);
+ *contents = leveldb::Slice(tmp.data(), tmp.size());
+ return result;
}
inline void WriteTableName(std::string *dest, const char *tableName) {
diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm
index 74463ee..dbe58e8 100644
--- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm
+++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm
@@ -34,12 +34,10 @@
#import "Firestore/Source/Model/FSTPath.h"
#import "Firestore/Source/Util/FSTAssert.h"
-#include "Firestore/Port/ordered_code.h"
#include "Firestore/core/src/firebase/firestore/util/string_util.h"
NS_ASSUME_NONNULL_BEGIN
-using Firestore::OrderedCode;
using Firestore::StringView;
using leveldb::DB;
using leveldb::Iterator;
diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm
index 5feb9f1..46af918 100644
--- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm
+++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm
@@ -29,11 +29,8 @@
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Util/FSTAssert.h"
-#include "Firestore/Port/ordered_code.h"
-
NS_ASSUME_NONNULL_BEGIN
-using Firestore::OrderedCode;
using Firestore::StringView;
using leveldb::DB;
using leveldb::Iterator;
diff --git a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm
index 039712c..b842cb5 100644
--- a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm
+++ b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm
@@ -32,11 +32,8 @@
#import "Firestore/Source/Model/FSTPath.h"
#import "Firestore/Source/Util/FSTAssert.h"
-#include "Firestore/Port/ordered_code.h"
-
NS_ASSUME_NONNULL_BEGIN
-using Firestore::OrderedCode;
using leveldb::DB;
using leveldb::Iterator;
using leveldb::ReadOptions;
diff --git a/Firestore/Source/Local/FSTWriteGroup.mm b/Firestore/Source/Local/FSTWriteGroup.mm
index 6859d53..80d09ca 100644
--- a/Firestore/Source/Local/FSTWriteGroup.mm
+++ b/Firestore/Source/Local/FSTWriteGroup.mm
@@ -23,9 +23,6 @@
#import "Firestore/Source/Local/FSTLevelDBKey.h"
#import "Firestore/Source/Util/FSTAssert.h"
-#include "Firestore/Port/ordered_code.h"
-
-using Firestore::OrderedCode;
using Firestore::StringView;
using leveldb::DB;
using leveldb::Slice;
diff --git a/Firestore/Source/Local/StringView.h b/Firestore/Source/Local/StringView.h
index b81b7b5..8156193 100644
--- a/Firestore/Source/Local/StringView.h
+++ b/Firestore/Source/Local/StringView.h
@@ -25,6 +25,7 @@
#include <leveldb/slice.h>
#include <string>
+#include "absl/strings/string_view.h"
namespace Firestore {
@@ -64,6 +65,10 @@ class StringView {
StringView(leveldb::Slice slice) : data_(slice.data()), size_(slice.size()) {
}
+ // Creates a StringView from the absl::string_view.
+ StringView(absl::string_view s) : data_(s.data()), size_(s.size()) {
+ }
+
// Creates a StringView from the given std::string. The string must be an
// lvalue for the lifetime requirements to be satisfied.
StringView(const std::string &str) : data_(str.data()), size_(str.size()) {
@@ -76,6 +81,13 @@ class StringView {
return leveldb::Slice(data_, size_);
}
+ // Converts this StringView to a absl::string_view, which is an equivalent (and more
+ // functional) type. The returned string_view has the same lifetime as this
+ // StringView.
+ operator absl::string_view() {
+ return absl::string_view(data_, size_);
+ }
+
private:
const char *data_;
const size_t size_;