| 1274 | }; |
| 1275 | |
| 1276 | fl::string json::to_string_native() const { |
| 1277 | if (!mValue) { |
| 1278 | return "null"; |
| 1279 | } |
| 1280 | |
| 1281 | // Use fl::deque for memory-efficient JSON serialization |
| 1282 | fl::deque<char> json_chars; |
| 1283 | |
| 1284 | // Use the visitor to serialize the value recursively |
| 1285 | SerializerVisitor visitor{json_chars}; |
| 1286 | visitor.serialize_value(mValue.get()); |
| 1287 | |
| 1288 | // Convert deque to fl::string efficiently |
| 1289 | fl::string result; |
| 1290 | if (!json_chars.empty()) { |
| 1291 | result.assign(&json_chars[0], json_chars.size()); |
| 1292 | } |
| 1293 | |
| 1294 | return result; |
| 1295 | } |
| 1296 | |
| 1297 | // Forward declaration for the serializeValue function |
| 1298 | fl::string serializeValue(const json_value& value); |