-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
PERF: fix performance regression from #62542 #62623
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
be21b2e
fc10a5f
ab2fab8
7e8033d
5219386
4ff07e3
c7fc292
4c8d770
35f075a
448f944
cf0a26d
2e5a47c
ca32c01
46c9883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1834,6 +1834,21 @@ int uint64_conflict(uint_state *self) { | |
return self->seen_uint && (self->seen_sint || self->seen_null); | ||
} | ||
|
||
static inline void check_for_invalid_char(const char *p_item, int *error) { | ||
while (*p_item != '\0' && isdigit_ascii(*p_item)) { | ||
p_item++; | ||
} | ||
|
||
while (*p_item != '\0' && isspace_ascii(*p_item)) { | ||
|
||
++p_item; | ||
} | ||
|
||
// check if reached the end of string after consuming all digits | ||
if (*p_item != '\0') { | ||
*error = ERROR_INVALID_CHARS; | ||
} | ||
} | ||
|
||
int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max, | ||
int *error, char tsep) { | ||
const char *p = p_item; | ||
|
@@ -1879,6 +1894,7 @@ int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max, | |
d = *++p; | ||
} else { | ||
*error = ERROR_OVERFLOW; | ||
check_for_invalid_char(p, error); | ||
return 0; | ||
} | ||
} | ||
|
@@ -1890,6 +1906,7 @@ int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max, | |
d = *++p; | ||
} else { | ||
*error = ERROR_OVERFLOW; | ||
check_for_invalid_char(p, error); | ||
return 0; | ||
} | ||
} | ||
|
@@ -1917,6 +1934,7 @@ int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max, | |
|
||
} else { | ||
*error = ERROR_OVERFLOW; | ||
check_for_invalid_char(p, error); | ||
return 0; | ||
} | ||
} | ||
|
@@ -1929,6 +1947,7 @@ int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max, | |
|
||
} else { | ||
*error = ERROR_OVERFLOW; | ||
check_for_invalid_char(p, error); | ||
return 0; | ||
} | ||
} | ||
|
@@ -1997,6 +2016,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, | |
|
||
} else { | ||
*error = ERROR_OVERFLOW; | ||
check_for_invalid_char(p, error); | ||
return 0; | ||
} | ||
} | ||
|
@@ -2009,6 +2029,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, | |
|
||
} else { | ||
*error = ERROR_OVERFLOW; | ||
check_for_invalid_char(p, error); | ||
return 0; | ||
} | ||
} | ||
|
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.
Can you document what this function does? The name
check_for_invalid_char
is a bit too vague - this is better described as something likecast_char_p_as_float
no?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.
I'd also suggest that you either return int and drop the
int *
argument, or return something useful (ex: return the parsed float value) and then set the pointer valueThere 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.
I added a Doxygen comment. It's also returning the pointer to the last verified character.
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.
I kept the error pointer in the function to prevent code duplication, and also because the main purpose of the function is just to assign a value to it. Considering that it's now returning the position of the last verified character, it's possible to change the error value outside the function, but I think it's more clean the way it is.
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.
Why is it returning a char *? It doesn't look like you are using the return value anywhere.
I'm leaning more towards the former approach unless there is a reason for it to return a value; its really common practice to return an integral code to denote an error or not (even in C++ you'll see Arrow do this all over the place). Tucking that return value away in a pointer is far less common.
Its also more performant to return the int value directly, although in this particular case that's probably too far down the stack to be noticable
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.
I changed it to return a status code.