Skip to content

Commit e277ef8

Browse files
committed
Use Ref<> in Fleece code
Converted some `Retained` into `Ref`s. Fixed a template method in ValueSlot that didn't work with `Ref`.
1 parent 71527ee commit e277ef8

8 files changed

Lines changed: 21 additions & 23 deletions

File tree

Fleece/Core/Builder.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ namespace fleece::impl::builder {
4848
RetainedConst<Value> buildValue() {
4949
switch (peekToken()) {
5050
case '[': {
51-
Retained<MutableArray> array = MutableArray::newArray();
51+
Ref<MutableArray> array = MutableArray::newArray();
5252
_buildInto(array);
5353
finished();
5454
return array.get();
5555
}
5656
case '{': {
57-
Retained<MutableDict> dict = MutableDict::newDict();
57+
Ref<MutableDict> dict = MutableDict::newDict();
5858
_buildInto(dict);
5959
finished();
6060
return dict.get();
@@ -82,13 +82,13 @@ namespace fleece::impl::builder {
8282
bool _buildValue(ValueSlot &inSlot) {
8383
switch (peekValue()) {
8484
case ValueType::array: {
85-
Retained<MutableArray> array = MutableArray::newArray();
85+
Ref<MutableArray> array = MutableArray::newArray();
8686
_buildInto(array);
8787
inSlot.set(array);
8888
break;
8989
}
9090
case ValueType::dict: {
91-
Retained<MutableDict> dict = MutableDict::newDict();
91+
Ref<MutableDict> dict = MutableDict::newDict();
9292
_buildInto(dict);
9393
inSlot.set(dict);
9494
break;

Fleece/Core/Doc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ namespace fleece { namespace impl {
350350
}
351351

352352

353-
Retained<Doc> Doc::fromFleece(const alloc_slice &fleece, Trust trust) {
353+
Ref<Doc> Doc::fromFleece(const alloc_slice &fleece, Trust trust) {
354354
return new Doc(fleece, trust);
355355
}
356356

357-
Retained<Doc> Doc::fromJSON(slice json, SharedKeys *sk) {
357+
Ref<Doc> Doc::fromJSON(slice json, SharedKeys *sk) {
358358
return new Doc(JSONConverter::convertJSON(json, sk), kTrusted, sk);
359359
}
360360

Fleece/Core/Doc.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ namespace fleece { namespace impl {
109109
slice subData,
110110
Trust =kUntrusted) noexcept;
111111

112-
static Retained<Doc> fromFleece(const alloc_slice &fleece, Trust =kUntrusted);
113-
static Retained<Doc> fromJSON(slice json, SharedKeys* =nullptr);
112+
static Ref<Doc> fromFleece(const alloc_slice &fleece, Trust =kUntrusted);
113+
static Ref<Doc> fromJSON(slice json, SharedKeys* =nullptr);
114114

115115
static RetainedConst<Doc> containing(const Value* NONNULL) noexcept;
116116

Fleece/Core/Encoder.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,11 @@ namespace fleece { namespace impl {
146146
return out;
147147
}
148148

149-
Retained<Doc> Encoder::finishDoc() {
150-
Retained<Doc> doc = new Doc(finish(),
151-
Doc::kTrusted,
152-
_sharedKeys,
153-
(_markExternPtrs ? _base : slice()));
154-
return doc;
149+
Ref<Doc> Encoder::finishDoc() {
150+
return new Doc(finish(),
151+
Doc::kTrusted,
152+
_sharedKeys,
153+
(_markExternPtrs ? _base : slice()));
155154
}
156155

157156
// Returns position in the stream of the next write. Pads stream to even pos if necessary.

Fleece/Core/Encoder.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace fleece { namespace impl {
6767
alloc_slice finish();
6868

6969
/** Returns the encoded data as a Doc. This implicitly calls end(). */
70-
Retained<Doc> finishDoc();
70+
Ref<Doc> finishDoc();
7171

7272
/** Resets the encoder so it can be used again. */
7373
void reset();

Fleece/Mutable/MutableArray.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ namespace fleece { namespace impl {
2424
public:
2525

2626
/** Creates a new array of size `initialCount` filled with null Values. */
27-
static Retained<MutableArray> newArray(uint32_t initialCount =0) {
27+
static Ref<MutableArray> newArray(uint32_t initialCount =0) {
2828
return (new internal::HeapArray(initialCount))->asMutableArray();
2929
}
3030

3131
/** Creates a copy of `a`, or an empty array if `a` is null.
3232
If `deepCopy` is true, nested mutable collections will be recursively copied too. */
33-
static Retained<MutableArray> newArray(const Array *a, CopyFlags flags =kDefaultCopy) {
33+
static Ref<MutableArray> newArray(const Array *a, CopyFlags flags =kDefaultCopy) {
3434
auto ha = retained(new internal::HeapArray(a));
3535
if (flags)
3636
ha->copyChildren(flags);
3737
return ha->asMutableArray();
3838
}
3939

40-
Retained<MutableArray> copy(CopyFlags f = kDefaultCopy) {return newArray(this, f);}
40+
Ref<MutableArray> copy(CopyFlags f = kDefaultCopy) {return newArray(this, f);}
4141

4242
const Array* source() const {return heapArray()->_source;}
4343
bool isChanged() const {return heapArray()->isChanged();}

Fleece/Mutable/MutableDict.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ namespace fleece { namespace impl {
2121
class MutableDict : public Dict {
2222
public:
2323

24-
static Retained<MutableDict> newDict(const Dict *d =nullptr, CopyFlags flags =kDefaultCopy) {
24+
static Ref<MutableDict> newDict(const Dict *d =nullptr, CopyFlags flags =kDefaultCopy) {
2525
return retained(new internal::HeapDict(d, flags))->asMutableDict();
2626
}
2727

28-
Retained<MutableDict> copy(CopyFlags f =kDefaultCopy) {return newDict(this, f);}
28+
Ref<MutableDict> copy(CopyFlags f =kDefaultCopy) {return newDict(this, f);}
2929

3030
const Dict* source() const {return heapDict()->_source;}
3131
bool isChanged() const {return heapDict()->isChanged();}

Fleece/Mutable/ValueSlot.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ namespace fleece { namespace impl {
5757

5858
// These methods allow set(Value*) to be called, without allowing any other pointer type
5959
// to be used; without them, set(Foo*) would incorrectly call set(bool).
60-
template <class T> void set(const T* t) {setValue(t);}
61-
template <class T> void set(const Retained<T> &t) {setValue(t);}
62-
template <class T> void set(const RetainedConst<T> &t) {setValue(t);}
60+
template <class T> void set(const T* t) {setValue(t);}
61+
template <class T, Nullability N> void set(const Retained<T,N> &t) {setValue(t);}
6362

6463
/** Replaces an external value with a copy of itself. */
6564
void copyValue(CopyFlags);

0 commit comments

Comments
 (0)