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

Add bunch of nitpicky micro-optimizations #17967

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

Add bunch of nitpicky micro-optimizations

How did you verify your code works?

@robobun
Copy link

robobun commented Mar 7, 2025

Updated 1:20 AM PT - Mar 7th, 2025

@Jarred-Sumner, your commit fa19bce has 3 failures in Build #12836:


🧪   try this PR locally:

bunx bun-pr 17967

@Jarred-Sumner Jarred-Sumner requested a review from nektro March 7, 2025 08:27
@@ -299,6 +299,12 @@ static WebCore::BufferEncodingType parseEncoding(JSC::ThrowScope& scope, JSC::JS
uint32_t validateOffset(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, JSC::JSValue name, uint32_t min, uint32_t max)
{
if (UNLIKELY(!value.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value);
if (value.isInt32()) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (value.isInt32()) {
if (LIKELY(value.isInt32())) {

@@ -308,6 +314,12 @@ uint32_t validateOffset(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObjec
uint32_t validateOffset(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, JSC::JSValue value, WTF::ASCIILiteral name, uint32_t min, uint32_t max)
{
if (UNLIKELY(!value.isNumber())) return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, name, "number"_s, value);
if (value.isInt32()) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (value.isInt32()) {
if (LIKELY(value.isInt32())) {

ASSERT_WITH_MESSAGE(upper.isInt32(), "upper must be an integer. Make sure constants set it to a jsNumber().");
auto lower_num = lower.asInt32();
auto upper_num = upper.asInt32();
if (number_num < lower_num || number_num > upper_num) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (number_num < lower_num || number_num > upper_num) {
if (UNLIKELY(number_num < lower_num || number_num > upper_num)) {

auto minLength_num = minLength.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, {});
if (length_num < minLength_num) {
if (length < minLength_num) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (length < minLength_num) {
if (UNLIKELY(length < minLength_num)) {

auto minLength_num = minLength.toNumber(globalObject);
RETURN_IF_EXCEPTION(scope, {});
if (length_num < minLength_num) {
if (length < minLength_num) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (length < minLength_num) {
if (UNLIKELY(length < minLength_num)) {

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.

3 participants