1 // Copyright 2020 The Abseil Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #include "absl/strings/internal/cord_internal.h" 15 16 #include <atomic> 17 #include <cassert> 18 #include <memory> 19 20 #include "absl/base/internal/raw_logging.h" 21 #include "absl/container/inlined_vector.h" 22 #include "absl/strings/internal/cord_rep_btree.h" 23 #include "absl/strings/internal/cord_rep_crc.h" 24 #include "absl/strings/internal/cord_rep_flat.h" 25 #include "absl/strings/internal/cord_rep_ring.h" 26 #include "absl/strings/str_cat.h" 27 28 namespace absl { 29 ABSL_NAMESPACE_BEGIN 30 namespace cord_internal { 31 32 ABSL_CONST_INIT std::atomic<bool> cord_ring_buffer_enabled( 33 kCordEnableRingBufferDefault); 34 ABSL_CONST_INIT std::atomic<bool> shallow_subcords_enabled( 35 kCordShallowSubcordsDefault); 36 LogFatalNodeType(CordRep * rep)37void LogFatalNodeType(CordRep* rep) { 38 ABSL_INTERNAL_LOG(FATAL, absl::StrCat("Unexpected node type: ", 39 static_cast<int>(rep->tag))); 40 } 41 Destroy(CordRep * rep)42void CordRep::Destroy(CordRep* rep) { 43 assert(rep != nullptr); 44 45 while (true) { 46 assert(!rep->refcount.IsImmortal()); 47 if (rep->tag == BTREE) { 48 CordRepBtree::Destroy(rep->btree()); 49 return; 50 } else if (rep->tag == RING) { 51 CordRepRing::Destroy(rep->ring()); 52 return; 53 } else if (rep->tag == EXTERNAL) { 54 CordRepExternal::Delete(rep); 55 return; 56 } else if (rep->tag == SUBSTRING) { 57 CordRepSubstring* rep_substring = rep->substring(); 58 rep = rep_substring->child; 59 delete rep_substring; 60 if (rep->refcount.Decrement()) { 61 return; 62 } 63 } else if (rep->tag == CRC) { 64 CordRepCrc::Destroy(rep->crc()); 65 return; 66 } else { 67 assert(rep->IsFlat()); 68 CordRepFlat::Delete(rep); 69 return; 70 } 71 } 72 } 73 74 } // namespace cord_internal 75 ABSL_NAMESPACE_END 76 } // namespace absl 77