Skip to content

more: replace InputType enum with Input struct; cache file_size#12225

Merged
sylvestre merged 1 commit into
uutils:mainfrom
aaron-ang:more-input-struct
May 11, 2026
Merged

more: replace InputType enum with Input struct; cache file_size#12225
sylvestre merged 1 commit into
uutils:mainfrom
aaron-ang:more-input-struct

Conversation

@aaron-ang
Copy link
Copy Markdown
Contributor

@aaron-ang aaron-ang commented May 11, 2026

Motivation

The pager dispatched between BufReader<File> and Stdin via a 2-variant enum, and called metadata() every time someone asked for the file size — even though the answer never changes during the run.

Changes

  • Replace enum InputType with a struct Input holding a Box<dyn BufRead> plus a cached file_size: Option<u64>, populated once at construction.
  • Constructors Input::from_file (reads metadata().len()) and Input::from_stdin (size unknown).
  • Input::len() now returns Option<u64> instead of Result<Option<u64>> — the only fallible call (metadata()) is gone.
  • Drop the duplicate Pager::file_size field; draw_status_bar reads from self.input.len() directly.
  • Pager::new no longer returns UResult<Self> — nothing inside it can fail anymore.

Drive-by

  • Rename page_resizeresize_page (verb-first matches every other Pager::* method).
  • Promote MULTI_FILE_TOP_PROMPT block comment to a doc comment.

Carved out from #10667 per the request to split.

InputType used a 2-variant enum to dispatch read_line/len; len() returned
Result<Option<u64>> because metadata() was called on every invocation.
Replace with a single Input struct holding Box<dyn BufRead> plus a cached
file_size, computed once at construction. Pager::new no longer needs to
return UResult since the only fallible call is gone.

Drive-by: rename page_resize -> resize_page (verb-first matches every
other Pager method); upgrade MULTI_FILE_TOP_PROMPT comment to a doc
comment.
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

@sylvestre sylvestre merged commit 95c78a5 into uutils:main May 11, 2026
171 checks passed
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.

2 participants