Use string view when appropriate.#11567
Merged
trivialfis merged 8 commits intodmlc:masterfrom Jul 22, 2025
Merged
Conversation
Member
trivialfis
commented
Jul 17, 2025
- Add tests for string utilities.
- Add tests for string utilities.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances common string utilities by introducing std::string_view variants, refactors version parsing for CUDA utilities, updates memory logging, and adds corresponding tests.
- Add
std::string_viewoverloads forSplit,TrimFirst, andTrimLastand clean up includes incommon.h - Replace
std::stoiwithstd::from_charsincuda_dr_utils.ccfor driver version parsing - Use
common::HumanMemUnitin quantile logging and bump copyright to 2025 - Add tests in
test_common.cccovering bothstd::stringandstd::string_viewfor trim and split functions
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/cpp/common/test_common.cc | Add includes for <string_view> and new tests for trim/split |
| src/common/quantile.cuh | Bump copyright year and update logging to use HumanMemUnit |
| src/common/cuda_dr_utils.cc | Swap std::stoi for std::from_chars in version parsing |
| src/common/common.h | Introduce string_view overloads for Split and Trim* |
Comments suppressed due to low confidence (3)
tests/cpp/common/test_common.cc:25
- [nitpick] The test case name 'Trim' is ambiguous since it covers both TrimFirst and TrimLast for different types. Consider splitting into distinct tests (e.g., 'TrimFirst' and 'TrimLast') or renaming to better reflect the combined functionality.
TEST(Common, Trim) {
tests/cpp/common/test_common.cc:25
- The trim function tests don’t cover edge cases such as empty strings or inputs containing only whitespace. Add test scenarios for these edge cases for both
std::stringandstd::string_viewoverloads.
TEST(Common, Trim) {
src/common/common.h:90
- [nitpick] Add a documentation comment above
TrimLastto explain that it trims trailing whitespace and returns astd::string_viewof the result.
[[nodiscard]] inline std::string_view TrimLast(std::string_view const &str) {
Collaborator
|
Is it possible to replace |
Member
Author
|
I did a trick with the custom string view and JSON #8332 |
hcho3
approved these changes
Jul 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.