-
Notifications
You must be signed in to change notification settings - Fork 90
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
base: main
Are you sure you want to change the base?
Conversation
Important Auto Review SkippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
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. |
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(🤣)")? |
There was a problem hiding this comment.
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('🤣')
31e6bc2
to
99b1995
Compare
Fix coverage |
99b1995
to
8f0032b
Compare
@@ -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)) | |||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" | |||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
8f0032b
to
8bac1cc
Compare
8bac1cc
to
38356eb
Compare
@@ -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) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
Part of #299
This PR rename current
Char::from_int
toChar::from_int_safe
, and add a safe version ofChar::from_int(Int) -> Option[Char]