• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/str_cat.h"
26 
27 namespace absl {
28 ABSL_NAMESPACE_BEGIN
29 namespace cord_internal {
30 
31 ABSL_CONST_INIT std::atomic<bool> shallow_subcords_enabled(
32     kCordShallowSubcordsDefault);
33 
LogFatalNodeType(CordRep * rep)34 void LogFatalNodeType(CordRep* rep) {
35   ABSL_INTERNAL_LOG(FATAL, absl::StrCat("Unexpected node type: ",
36                                         static_cast<int>(rep->tag)));
37 }
38 
Destroy(CordRep * rep)39 void CordRep::Destroy(CordRep* rep) {
40   assert(rep != nullptr);
41 
42   while (true) {
43     assert(!rep->refcount.IsImmortal());
44     if (rep->tag == BTREE) {
45       CordRepBtree::Destroy(rep->btree());
46       return;
47     } else if (rep->tag == EXTERNAL) {
48       CordRepExternal::Delete(rep);
49       return;
50     } else if (rep->tag == SUBSTRING) {
51       CordRepSubstring* rep_substring = rep->substring();
52       rep = rep_substring->child;
53       delete rep_substring;
54       if (rep->refcount.Decrement()) {
55         return;
56       }
57     } else if (rep->tag == CRC) {
58       CordRepCrc::Destroy(rep->crc());
59       return;
60     } else {
61       assert(rep->IsFlat());
62       CordRepFlat::Delete(rep);
63       return;
64     }
65   }
66 }
67 
68 }  // namespace cord_internal
69 ABSL_NAMESPACE_END
70 }  // namespace absl
71