| 145 | } |
| 146 | |
| 147 | ByteString ByteString::Borrowed(Borrower borrower, absl::string_view string) { |
| 148 | ABSL_DCHECK(borrower != Borrower::None()) << "Borrowing from Owner::None()"; |
| 149 | auto* arena = borrower.arena(); |
| 150 | if (string.size() <= kSmallByteStringCapacity || arena != nullptr) { |
| 151 | return ByteString(arena, string); |
| 152 | } |
| 153 | const auto* refcount = BorrowerRelease(borrower); |
| 154 | // A nullptr refcount indicates somebody called us to borrow something that |
| 155 | // has no owner. If this is the case, we fallback to assuming operator |
| 156 | // new/delete and convert it to a reference count. |
| 157 | if (refcount == nullptr) { |
| 158 | std::tie(refcount, string) = MakeReferenceCountedString(string); |
| 159 | } else { |
| 160 | StrongRef(*refcount); |
| 161 | } |
| 162 | return ByteString(refcount, string); |
| 163 | } |
| 164 | |
| 165 | ByteString ByteString::Borrowed(Borrower borrower, const absl::Cord& cord) { |
| 166 | ABSL_DCHECK(borrower != Borrower::None()) << "Borrowing from Owner::None()"; |
nothing calls this directly
no test coverage detected