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

use a better way to check whether string is empty #315

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

iuhilnehc-ynos
Copy link
Collaborator

@iuhilnehc-ynos iuhilnehc-ynos commented Nov 12, 2020

call strlen twice at

rcutils/src/split.c

Lines 41 to 47 in 4c53476

if (NULL == str || strlen(str) == 0) {
*string_array = rcutils_get_zero_initialized_string_array();
return RCUTILS_RET_OK;
}
string_array->allocator = allocator;
size_t string_size = strlen(str);
, I believe L41 can be updated from strlen to '\0' == *str

Signed-off-by: Chen Lihui lihui.chen@sony.com

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

In the case where this is an empty string, this may be slightly faster, since a function call doesn't have to be made.

But in the case where it is a non-empty string, this will be substantially faster; it is constant time rather than the length of the string.

Works for me. I'll run CI on it next.

@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

The macOS failure happened in the nightly as well: https://ci.ros2.org/view/nightly/job/nightly_osx_release/1869/

Windows also had failures (its a bit random on Windows, but in the last week or so all of the failures also failed): https://ci.ros2.org/view/nightly/job/nightly_win_rel/1750/

With that, I'm going to merge this. Thanks for the contribution.

@clalancette clalancette merged commit 7753eed into ros2:master Nov 12, 2020
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