[AI Task] [Tizen.Multimedia.Recorder] Remove params allocation from Recorder.ValidateState#7697
[AI Task] [Tizen.Multimedia.Recorder] Remove params allocation from Recorder.ValidateState#7697JoonghyunCho wants to merge 1 commit into
Conversation
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>
There was a problem hiding this comment.
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.
|
🤖 [AI Review] Reviewed — no findings. Scope checked:
No 🔴 critical issues, no 🟡 suggestions to flag. Automated review — final merge decision rests with human reviewers. |
Summary
Recorder.ValidateState(params RecorderState[] required)allocated a newRecorderState[]on every call because of theparamsarray. 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
paramsoverload is kept for the 3+ argument case, and the exception-message construction moves to a cold[DoesNotReturn]ThrowInvalidStatehelper so the success path allocates nothing. This mirrors the AudioIO fix in #7609.Changes
src/Tizen.Multimedia.Recorder/Recorder/Recorder.csValidateState(RecorderState)andValidateState(RecorderState, RecorderState)zero-alloc overloads.ValidateState(params RecorderState[]); switch its check from LINQ!ContainstoArray.IndexOf(...) < 0.[DoesNotReturn] ThrowInvalidStatehelper (identical exception message).using System.Linq;, addusing 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
dotnet build -c ReleaseonTizen.Multimedia.Recorder, 0 errors)sdb deviceslists none). Manual benchmark verification required.Fixes #7640