Add method to efficiently convert strings#415
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new helper for converting JSI strings to std::string and wires it into the native bindings, while also updating the example app/tooling (notably a React Native upgrade) and adjusting the example performance benchmark harness.
Changes:
- Add
jsi_string_to_utf8()(based onjsi::String::getStringData) and replace many.utf8(rt)call sites with it. - Update the example benchmark to populate more rows and run the benchmark automatically from the example app.
- Upgrade React/React Native and related ecosystem/tooling (Metro/CLI/Hermes, CocoaPods/Gradle configs, lockfiles).
Reviewed changes
Copilot reviewed 15 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
yarn.lock |
Updates lockfile entries consistent with the dependency upgrades (React/React Native ecosystem). |
package.json |
Bumps root dev dependencies (React/React Native). |
example/src/performance_test.ts |
Changes benchmark setup (inserts many rows) and timing logic. |
example/src/App.tsx |
Runs the performance test automatically after tests complete; displays timing. |
example/package.json |
Updates example dependencies/tooling versions and modifies iOS helper scripts. |
example/ios/Podfile.lock |
Reflects CocoaPods dependency changes from the RN/Hermes upgrade. |
example/ios/OPSQLiteExample/Info.plist |
Uses Xcode build variables for versions; tweaks device/orientation settings. |
example/ios/OPSQLiteExample.xcodeproj/project.pbxproj |
Adds flags/settings aligned with newer RN templates (e.g., legacy arch removal). |
example/Gemfile.lock |
Updates Ruby dependencies (adds nkf, bumps bundler). |
example/Gemfile |
Adds nkf. |
example/android/gradle/wrapper/gradle-wrapper.properties |
Bumps Gradle wrapper version. |
example/android/gradle.properties |
Adjusts Android build flags (Jetifier removal, edge-to-edge flag, etc.). |
example/android/build.gradle |
Bumps Android SDK/build tools and Kotlin version. |
example/android/app/src/main/kotlin/com/op/sqlite/example/MainApplication.kt |
Updates app init to newer RN entrypoint API. |
cpp/utils.hpp |
Adds the new JSI string conversion helper implementation. |
cpp/utils.cpp |
Switches variant/string conversions to use jsi_string_to_utf8(). |
cpp/OPSqlite.cpp |
Switches option string extraction to use jsi_string_to_utf8(). |
cpp/DBHostObject.cpp |
Switches multiple JSI string extractions to use jsi_string_to_utf8(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+22
to
+45
| struct JSIStringDataAppender { | ||
| std::string *out; | ||
|
|
||
| void operator()(bool ascii, const void *data, size_t num) const { | ||
| if (ascii) { | ||
| out->append(static_cast<const char *>(data), num); | ||
| return; | ||
| } | ||
|
|
||
| const auto *u16 = static_cast<const char16_t *>(data); | ||
| out->reserve(out->size() + num); | ||
| for (size_t i = 0; i < num; i++) { | ||
| out->push_back(static_cast<char>(u16[i])); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| inline std::string jsi_string_to_utf8(jsi::Runtime &rt, | ||
| const jsi::String &value) { | ||
| std::string result; | ||
| JSIStringDataAppender cb{&result}; | ||
| value.getStringData(rt, cb); | ||
| return result; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
As intended, JS effectively uses utf-8 but the retarded decision at the beginning of the universe was to use utf-16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a method to efficiently convert strings based on the work of @GrzywN specified here, performance gains on a simple test seem minor, but they might compound with larger string inputs.