Skip to content

[AI Task] [Tizen.Multimedia.Recorder] Remove params allocation from Recorder.ValidateState#7697

Open
JoonghyunCho wants to merge 1 commit into
mainfrom
ai-task/issue-7640
Open

[AI Task] [Tizen.Multimedia.Recorder] Remove params allocation from Recorder.ValidateState#7697
JoonghyunCho wants to merge 1 commit into
mainfrom
ai-task/issue-7640

Conversation

@JoonghyunCho

Copy link
Copy Markdown
Member

Summary

Recorder.ValidateState(params RecorderState[] required) allocated a new RecorderState[] on every call because of the params array. It is called from ~19 hot sites (Prepare/Unprepare/Start/Pause/Resume/Commit/Cancel, property setters, VideoRecorder), and all of them pass 1 or 2 states — so rapid Pause/Resume toggling or quick setter sequences accumulate small short-lived arrays in Gen0.

This adds zero-alloc single- and two-argument overloads that the compiler dispatches to automatically (no call-site changes). The params overload is kept for the 3+ argument case, and the exception-message construction moves to a cold [DoesNotReturn] ThrowInvalidState helper so the success path allocates nothing. This mirrors the AudioIO fix in #7609.

Changes

  • src/Tizen.Multimedia.Recorder/Recorder/Recorder.cs
    • Add ValidateState(RecorderState) and ValidateState(RecorderState, RecorderState) zero-alloc overloads.
    • Keep ValidateState(params RecorderState[]); switch its check from LINQ !Contains to Array.IndexOf(...) < 0.
    • Extract the throw path into a [DoesNotReturn] ThrowInvalidState helper (identical exception message).
    • Drop the now-unused using System.Linq;, add using System.Diagnostics.CodeAnalysis;.

Call sites are unchanged — overload resolution dispatches 1/2-arg calls to the new allocation-free overloads. Behavior is preserved: the 1-arg check (!=), 2-arg check (&& !=), and params check (Array.IndexOf < 0) are all equivalent to the original !required.Contains(curState), and the exception message is byte-for-byte identical.

Mode

Refactoring

Verification

  • Build: passed (dotnet build -c Release on Tizen.Multimedia.Recorder, 0 errors)
  • Tests: N/A (internal method; no behavior or public API change)
  • Benchmark: skipped (sdb error: no device connected — sdb devices lists none). Manual benchmark verification required.

Fixes #7640

ValidateState(params RecorderState[]) allocated a fresh RecorderState[] on
every call. All 19 call sites pass 1 or 2 states, so add zero-alloc
single- and two-argument overloads that the compiler dispatches to
automatically. The params overload is retained for 3+ arguments, and the
exception-message build moves to a cold [DoesNotReturn] ThrowInvalidState
helper so the success path allocates nothing. Mirrors the AudioIO fix in #7609.

Fixes #7640

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes state validation in the Recorder class by adding overloads for ValidateState that avoid array allocation (for single and double state checks) and replacing LINQ's Contains with Array.IndexOf for the params overload. Additionally, it extracts the exception throwing logic into a helper method annotated with [DoesNotReturn]. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@JoonghyunCho

Copy link
Copy Markdown
Member Author

🤖 [AI Review]

Reviewed — no findings.

Scope checked:

  • Behavior preserved: the new 1-arg and 2-arg ValidateState overloads apply identical equality checks; calls with 3+ states still resolve to the retained params overload.
  • Array.IndexOf(required, curState) < 0 is an equivalent replacement for the removed required.Contains(...), and the now-unused using System.Linq; was correctly dropped.
  • Exception type (InvalidOperationException) and message text are unchanged, now centralized in the [DoesNotReturn] ThrowInvalidState helper.
  • All affected members are internal/private — no public API surface or XML-doc impact.

No 🔴 critical issues, no 🟡 suggestions to flag.


Automated review — final merge decision rests with human reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant