Skip to content

Refactor repetitive method calls and standardize UChar buffer retry logic#359

Open
filmil wants to merge 1 commit into
mainfrom
refactor-ulistformatter-macro-2703538365688145281
Open

Refactor repetitive method calls and standardize UChar buffer retry logic#359
filmil wants to merge 1 commit into
mainfrom
refactor-ulistformatter-macro-2703538365688145281

Conversation

@filmil
Copy link
Copy Markdown
Member

@filmil filmil commented May 11, 2026

Refactored the codebase to reduce code repetition and standardize the handling of ICU's buffer-resize-retry pattern for UChar strings.

Key Changes:

  • Centralized Helper: Added buffered_uchar_method_with_retry to rust_icu_ustring, providing a closure-based alternative to the existing macro for better flexibility.
  • Refactored ulistformatter: Introduced a more robust generate_format_methods! macro and removed repetitive manual implementations.
  • Improved Consistency: Refactored udat, umsg, and upluralrules to use the new standardized pattern, eliminating many lines of manual boilerplate.
  • Bug Fix: The new helper ensures that the buffer is correctly initialized with vec![0; capacity] before use, avoiding potential safety issues with uninitialized memory.
  • Cleanup: Removed obsolete TODOs and improved documentation.

PR created automatically by Jules for task 2703538365688145281 started by @filmil

This commit reduces code repetition across several crates by introducing
a centralized `buffered_uchar_method_with_retry` function in the
`rust_icu_ustring` crate. This function abstracts the common ICU pattern
of preflighting a buffer, resizing, and retrying on overflow.

Modified Crates:
- `rust_icu_ustring`: Added the `buffered_uchar_method_with_retry` helper.
- `rust_icu_ulistformatter`: Refactored to use a more flexible
  `generate_format_methods!` macro and the new global helper.
- `rust_icu_udat`: Replaced manual retry loops in `format` and timezone
  helpers with the new standardized function.
- `rust_icu_umsg`: Updated `format_args` to leverage the new helper.
- `rust_icu_upluralrules`: Simplified the `select` method for consistency.

This refactoring improves maintainability, reduces the surface area for
manual memory/buffer handling errors, and establishes a consistent pattern
across the workspace.

This commit was created by an automated coding assistant, with human supervision.

Co-authored-by: filmil <246576+filmil@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant