FreeBSDでの修正
諏訪子 <suwako@076.moe>、2026-06-30 02:44
コミット 6deba52c5b01dddeb7fff1b4d7ec6960b398912b
・親 02c53c7
・ファイルを見る
3個のファイル、+16 -13
| @@ -86,7 +86,7 @@ | ||
| 86 | 86 | auto end() const { return m_Data.end(); } |
| 87 | 87 | |
| 88 | 88 | private: |
| 89 | - using Pair = std::pair<string, Value>; | |
| 89 | + using Pair = std::pair<string, std::unique_ptr<Value>>; | |
| 90 | 90 | vector<Pair> m_Data; |
| 91 | 91 | std::unordered_map<string, size_t, StringHash, std::equal_to<>> m_Index; |
| 92 | 92 | }; // struct Object |
変更
src/json.cc
| @@ -207,11 +207,12 @@ | ||
| 207 | 207 | std::optional<f64> Parser::parse_number() { |
| 208 | 208 | cstr start = m_Text.data() + m_Pos; |
| 209 | 209 | f64 num = 0.0; |
| 210 | - auto [ptr, ec] = std::from_chars(start, m_Text.data() + m_Text.size(), num); | |
| 210 | + char *end = nullptr; | |
| 211 | + num = std::strtod(start, &end); | |
| 211 | 212 | |
| 212 | - if (ec != std::errc() || ptr == start) return std::nullopt; | |
| 213 | + if (end == start) return std::nullopt; | |
| 213 | 214 | |
| 214 | - m_Pos += (ptr - start); | |
| 215 | + m_Pos += (end - start); | |
| 215 | 216 | return num; |
| 216 | 217 | } |
| 217 | 218 | |
| @@ -297,7 +298,7 @@ | ||
| 297 | 298 | |
| 298 | 299 | out += serialize_string(key); |
| 299 | 300 | out += opts.pretty ? ": " : ":"; |
| 300 | - out += val.serialize_impl(opts, depth + 1); | |
| 301 | + out += val->serialize_impl(opts, depth + 1); | |
| 301 | 302 | |
| 302 | 303 | if (++i < obj.size()) |
| 303 | 304 | out += ","; |
| @@ -343,23 +344,25 @@ | ||
| 343 | 344 | } |
| 344 | 345 | |
| 345 | 346 | void Object::insert(string key, Value value) { |
| 347 | + auto ptr = std::make_unique<Value>(std::move(value)); | |
| 348 | + | |
| 346 | 349 | auto it = m_Index.find(key); |
| 347 | 350 | if (it != m_Index.end()) { |
| 348 | - m_Data[it->second].second = std::move(value); | |
| 351 | + m_Data[it->second].second = std::move(ptr); | |
| 349 | 352 | } else { |
| 350 | 353 | m_Index[key] = m_Data.size(); |
| 351 | - m_Data.emplace_back(std::move(key), std::move(value)); | |
| 354 | + m_Data.emplace_back(std::move(key), std::move(ptr)); | |
| 352 | 355 | } |
| 353 | 356 | } |
| 354 | 357 | |
| 355 | 358 | Value *Object::get(std::string_view key) { |
| 356 | 359 | auto it = m_Index.find(key); |
| 357 | - return it != m_Index.end() ? &m_Data[it->second].second : nullptr; | |
| 360 | + return it != m_Index.end() ? m_Data[it->second].second.get() : nullptr; | |
| 358 | 361 | } |
| 359 | 362 | |
| 360 | 363 | const Value *Object::get(std::string_view key) const { |
| 361 | 364 | auto it = m_Index.find(key); |
| 362 | - return it != m_Index.end() ? &m_Data[it->second].second : nullptr; | |
| 365 | + return it != m_Index.end() ? m_Data[it->second].second.get() : nullptr; | |
| 363 | 366 | } |
| 364 | 367 | |
| 365 | 368 | bool Object::contains(std::string_view key) const { |
| @@ -169,10 +169,10 @@ | ||
| 169 | 169 | assert(arr[0].as_object().get("componentType")->as_number() == 5123); |
| 170 | 170 | assert(arr[0].as_object().get("count")->as_number() == 3); |
| 171 | 171 | assert(arr[0].as_object().get("type")->as_string() == "SCALAR"); |
| 172 | - auto max0 = arr[0].as_object().get("max")->as_array(); | |
| 172 | + const auto &max0 = arr[0].as_object().get("max")->as_array(); | |
| 173 | 173 | assert(max0.size() == 1); |
| 174 | 174 | assert(max0[0].get_number() == 2); |
| 175 | - auto min0 = arr[0].as_object().get("min")->as_array(); | |
| 175 | + const auto &min0 = arr[0].as_object().get("min")->as_array(); | |
| 176 | 176 | assert(min0.size() == 1); |
| 177 | 177 | assert(min0[0].get_number() == 0); |
| 178 | 178 | |
| @@ -182,12 +182,12 @@ | ||
| 182 | 182 | assert(arr[1].as_object().get("componentType")->as_number() == 5126); |
| 183 | 183 | assert(arr[1].as_object().get("count")->as_number() == 3); |
| 184 | 184 | assert(arr[1].as_object().get("type")->as_string() == "VEC3"); |
| 185 | - auto max1 = arr[1].as_object().get("max")->as_array(); | |
| 185 | + const auto &max1 = arr[1].as_object().get("max")->as_array(); | |
| 186 | 186 | assert(max1.size() == 3); |
| 187 | 187 | assert(max1[0].get_number() == 1.0); |
| 188 | 188 | assert(max1[1].get_number() == 1.0); |
| 189 | 189 | assert(max1[2].get_number() == 0.0); |
| 190 | - auto min1 = arr[1].as_object().get("min")->as_array(); | |
| 190 | + const auto &min1 = arr[1].as_object().get("min")->as_array(); | |
| 191 | 191 | assert(min1.size() == 3); |
| 192 | 192 | assert(min1[0].get_number() == 0.0); |
| 193 | 193 | assert(min1[1].get_number() == 0.0); |