Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename Char::from_int to Char::from_int_unsafe #338

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lijunchen
Copy link
Contributor

@lijunchen lijunchen commented Apr 28, 2024

Part of #299

This PR rename current Char::from_int to Char::from_int_safe, and add a safe version of Char::from_int(Int) -> Option[Char]

Copy link
Contributor

coderabbitai bot commented Apr 28, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lijunchen lijunchen changed the base branch from main to lijunchen/remove-surrogate-related-in-char April 28, 2024 04:17
Copy link

codecov bot commented Apr 28, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 90.60%. Comparing base (24bf4ae) to head (38356eb).

Files Patch % Lines
string/string.mbt 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #338      +/-   ##
==========================================
+ Coverage   90.56%   90.60%   +0.03%     
==========================================
  Files          96       96              
  Lines        3605     3609       +4     
==========================================
+ Hits         3265     3270       +5     
+ Misses        340      339       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lijunchen lijunchen requested a review from bobzhang April 28, 2024 04:18
inspect(Char::from_int(20013), content="Some(中)")?
inspect(Char::from_int_unchecked(20013), content="中")?
inspect('🤣'.to_int(), content="129315")?
inspect(Char::from_int(129315), content="Some(🤣)")?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guest0x0 Some(🤣) should be Some('🤣')

Base automatically changed from lijunchen/remove-surrogate-related-in-char to main April 28, 2024 06:28
@lijunchen lijunchen force-pushed the lijunchen/rename-char-from-int branch 3 times, most recently from 31e6bc2 to 99b1995 Compare April 28, 2024 06:54
@lijunchen
Copy link
Contributor Author

Fix coverage

@lijunchen lijunchen force-pushed the lijunchen/rename-char-from-int branch from 99b1995 to 8f0032b Compare April 28, 2024 07:49
@@ -50,7 +50,7 @@ pub fn to_string(self : Int64) -> String {
if num2 != 0L {
write_digits(num2)
}
buf.write_char(Char::from_int(abs(num % 10L).to_int() + 48))
buf.write_char(Char::from_int_unchecked(abs(num % 10L).to_int() + 48))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this in perf critical place? if not, we would prefer safe API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but we cannot use Option::unwrap in builtin

@@ -184,7 +184,7 @@ pub fn Double::convert_i64_u(val : Int64) -> Double = "%i64_to_f64_u"

pub fn Char::to_int(self : Char) -> Int = "%char_to_int"

pub fn Char::from_int(val : Int) -> Char = "%char_from_int"
pub fn Char::from_int_unchecked(val : Int) -> Char = "%char_from_int"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this unsafe API does not be exposed, it can be pulled in on demand, so that it is only local to its used package

Copy link
Contributor Author

@lijunchen lijunchen May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my current implementation, it is used by coverage and json5. I think exposing Char::from_int_unsafe is reasonable.

@lijunchen lijunchen force-pushed the lijunchen/rename-char-from-int branch from 8f0032b to 8bac1cc Compare May 14, 2024 03:37
@lijunchen lijunchen force-pushed the lijunchen/rename-char-from-int branch from 8bac1cc to 38356eb Compare May 14, 2024 03:38
@@ -102,9 +102,9 @@ fn escape_to(s : String, buf : Buffer) -> Unit {

fn to_hex_digit(i : Int) -> Char {
if i < 10 {
Char::from_int('0'.to_int() + i)
Char::from_int_unsafe('0'.to_int() + i)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot use Option::unwrap here, because of cyclic dependencies

@@ -23,7 +23,7 @@ fn read_char(ctx : ParseContext) -> Option[Char] {
if c2 >= 0xDC00 && c2 <= 0xDFFF {
ctx.offset += 1
let c3 = c1.lsl(10) + c2 - 0x35fdc00
return Some(Char::from_int(c3))
return Some(Char::from_int_unsafe(c3))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe performance critical in json5 package

@lijunchen lijunchen requested a review from bobzhang May 14, 2024 03:47
@lijunchen lijunchen changed the title rename Char::from_int to Char::from_int_unchecked rename Char::from_int to Char::from_int_unsafe May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants