|
39 | 39 | #include <utility> |
40 | 40 | #include <vector> |
41 | 41 |
|
| 42 | +#include "absl/base/no_destructor.h" |
42 | 43 | #include "absl/flags/flag.h" |
43 | 44 | #include "absl/log/check.h" |
44 | 45 | #include "absl/log/log.h" |
|
53 | 54 | #include "base/init_mozc.h" |
54 | 55 | #include "base/number_util.h" |
55 | 56 | #include "base/protobuf/text_format.h" |
56 | | -#include "base/singleton.h" |
57 | 57 | #include "base/system_util.h" |
58 | 58 | #include "composer/composer.h" |
59 | 59 | #include "config/config_handler.h" |
@@ -112,31 +112,15 @@ int FindCandidate(const Segment& segment, absl::string_view value) { |
112 | 112 | return -1; |
113 | 113 | } |
114 | 114 |
|
115 | | -// Wrapper class for pos id printing |
116 | | -class PosIdPrintUtil { |
117 | | - public: |
118 | | - PosIdPrintUtil(const PosIdPrintUtil&) = delete; |
119 | | - PosIdPrintUtil& operator=(const PosIdPrintUtil&) = delete; |
120 | | - static std::string IdToString(int id) { |
121 | | - return Singleton<PosIdPrintUtil>::get()->IdToStringInternal(id); |
122 | | - } |
123 | | - |
124 | | - private: |
125 | | - PosIdPrintUtil() |
126 | | - : pos_id_printer_(InputFileStream(absl::GetFlag(FLAGS_id_def))) {} |
127 | | - |
128 | | - std::string IdToStringInternal(int id) const { |
129 | | - const absl::string_view pos_string = pos_id_printer_.IdToString(id); |
130 | | - if (pos_string.empty()) { |
131 | | - return absl::StrCat(id); |
132 | | - } |
133 | | - return absl::StrFormat("%s (%d)", pos_string, id); |
| 115 | +std::string IdToString(int id) { |
| 116 | + static const absl::NoDestructor<internal::PosIdPrinter> printer( |
| 117 | + internal::PosIdPrinter(InputFileStream(absl::GetFlag(FLAGS_id_def)))); |
| 118 | + const absl::string_view pos_string = printer->IdToString(id); |
| 119 | + if (pos_string.empty()) { |
| 120 | + return absl::StrCat(id); |
134 | 121 | } |
135 | | - |
136 | | - internal::PosIdPrinter pos_id_printer_; |
137 | | - |
138 | | - friend class Singleton<PosIdPrintUtil>; |
139 | | -}; |
| 122 | + return absl::StrFormat("%s (%d)", pos_string, id); |
| 123 | +} |
140 | 124 |
|
141 | 125 | std::string SegmentTypeToString(Segment::SegmentType type) { |
142 | 126 | #define RETURN_STR(val) \ |
@@ -230,8 +214,8 @@ void PrintCandidate(const Segment& parent, size_t candidates_size, int num, |
230 | 214 | cand.content_key); |
231 | 215 | lines.push_back(absl::StrFormat("cost: %d scost: %d wcost: %d", cand.cost, |
232 | 216 | cand.structure_cost, cand.wcost)); |
233 | | - lines.push_back("lid: " + PosIdPrintUtil::IdToString(cand.lid)); |
234 | | - lines.push_back("rid: " + PosIdPrintUtil::IdToString(cand.rid)); |
| 217 | + lines.push_back("lid: " + IdToString(cand.lid)); |
| 218 | + lines.push_back("rid: " + IdToString(cand.rid)); |
235 | 219 | lines.push_back("attr: " + CandidateAttributesToString(cand.attributes)); |
236 | 220 | lines.push_back("num_style: " + NumberStyleToString(cand.style)); |
237 | 221 | const std::string segbdd_str = InnerSegmentBoundaryToString(cand); |
|
0 commit comments