Skip to content

Commit

Permalink
Gotta use the same cursor for splits.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanHenson committed Oct 27, 2023
1 parent ae51717 commit 7ec3e9d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion source/byte_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ bool aws_byte_cursor_next_split(
/* substr is now remainder of string, search for next split */
uint8_t *new_location = memchr(substr->ptr, split_on, substr->len);
if (new_location) {

/* Character found, update string length. */
substr->len = new_location - substr->ptr;
}
Expand Down
28 changes: 18 additions & 10 deletions source/linux/system_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,15 @@ size_t aws_get_cpu_count_for_group(uint16_t group_idx) {
struct aws_byte_cursor range_cursor;
aws_array_list_get_at(&cpu_ranges, &range_cursor, i);
struct aws_byte_cursor start_cursor, end_cursor;
AWS_ZERO_STRUCT(start_cursor);
AWS_ZERO_STRUCT(end_cursor);
if (aws_byte_cursor_next_split(&range_cursor, '-', &start_cursor) &&
aws_byte_cursor_next_split(&range_cursor, '-', &end_cursor)) {
AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "static: Parsed cpu ranges " PRInSTR "-" PRInSTR " for node %" PRIu16, AWS_BYTE_CURSOR_PRI(start_cursor), AWS_BYTE_CURSOR_PRI(end_cursor), group_idx);
struct aws_byte_cursor split_cur;
AWS_ZERO_STRUCT(split_cur);
bool start_found = aws_byte_cursor_next_split(&range_cursor, '-', &split_cur);
start_cursor = split_cur;
bool end_found = aws_byte_cursor_next_split(&range_cursor, '-', &split_cur);
end_cursor = split_cur;

if (start_found && end_found) {
AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "static: Parsed cpu range " PRInSTR "-" PRInSTR " for node %" PRIu16, AWS_BYTE_CURSOR_PRI(start_cursor), AWS_BYTE_CURSOR_PRI(end_cursor), group_idx);
uint64_t start, end;
if (aws_byte_cursor_utf8_parse_u64(start_cursor, &start) == AWS_OP_SUCCESS &&
aws_byte_cursor_utf8_parse_u64(end_cursor, &end) == AWS_OP_SUCCESS) {
Expand Down Expand Up @@ -317,12 +321,16 @@ void aws_get_cpu_ids_for_group(uint16_t group_idx, struct aws_cpu_info *cpu_ids_
struct aws_byte_cursor range_cursor;
aws_array_list_get_at(&cpu_ranges, &range_cursor, i);
struct aws_byte_cursor start_cursor, end_cursor;
AWS_ZERO_STRUCT(start_cursor);
AWS_ZERO_STRUCT(end_cursor);
if (aws_byte_cursor_next_split(&range_cursor, '-', &start_cursor) &&
aws_byte_cursor_next_split(&range_cursor, '-', &end_cursor)) {
struct aws_byte_cursor split_cur;
AWS_ZERO_STRUCT(split_cur);
bool start_found = aws_byte_cursor_next_split(&range_cursor, '-', &split_cur);
start_cursor = split_cur;
bool end_found = aws_byte_cursor_next_split(&range_cursor, '-', &split_cur);
end_cursor = split_cur;

if (start_found && end_found) {
uint64_t start, end;
AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "static: Parsed cpu ranges " PRInSTR "-" PRInSTR " for node %" PRIu16, AWS_BYTE_CURSOR_PRI(start_cursor), AWS_BYTE_CURSOR_PRI(end_cursor), group_idx);
AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "static: Parsed cpu range " PRInSTR "-" PRInSTR " for node %" PRIu16, AWS_BYTE_CURSOR_PRI(start_cursor), AWS_BYTE_CURSOR_PRI(end_cursor), group_idx);
if (aws_byte_cursor_utf8_parse_u64(start_cursor, &start) == AWS_OP_SUCCESS &&
aws_byte_cursor_utf8_parse_u64(end_cursor, &end) == AWS_OP_SUCCESS) {
for (uint64_t j = start; j <= end && cpu_count < cpu_ids_array_length; ++j) {
Expand Down
2 changes: 1 addition & 1 deletion tests/split_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static int s_test_byte_cursor_range_split_str(struct aws_allocator *allocator, v
ASSERT_TRUE(aws_byte_cursor_next_split(&to_split1, '-', &result1));
ASSERT_CURSOR_VALUE_CSTRING_EQUALS(result1, "0");

ASSERT_TRUE(aws_byte_cursor_next_split(&to_split1, '1', &result1));
ASSERT_TRUE(aws_byte_cursor_next_split(&to_split1, '-', &result1));
ASSERT_CURSOR_VALUE_CSTRING_EQUALS(result1, "9");

ASSERT_FALSE(aws_byte_cursor_next_split(&to_split1, '-', &result1));
Expand Down

0 comments on commit 7ec3e9d

Please sign in to comment.