Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/Tizen.Multimedia.Camera/Camera/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,33 @@ internal void ValidateNotDisposed()
}
#endregion Dispose support

internal void ValidateState(params CameraState[] required)
internal void ValidateState(CameraState required)
{
ValidateNotDisposed();

Debug.Assert(required.Length > 0);
var curState = _state;
if (curState != required)
{
ThrowInvalidState(curState, required);
}
}

internal void ValidateState(CameraState required1, CameraState required2)
{
ValidateNotDisposed();

var curState = _state;
if (!required.Contains(curState))
if (curState != required1 && curState != required2)
{
throw new InvalidOperationException($"The camera is not in a valid state. " +
$"Current State : { curState }, Valid State : { string.Join(", ", required) }.");
ThrowInvalidState(curState, required1, required2);
}
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static void ThrowInvalidState(CameraState curState, params CameraState[] required) =>
throw new InvalidOperationException($"The camera is not in a valid state. " +
$"Current State : { curState }, Valid State : { string.Join(", ", required) }.");
Comment on lines +241 to +243

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To ensure that the hot-path validation methods (ValidateState) are highly eligible for JIT inlining, it is a recommended practice to mark the exception-throwing helper method with [MethodImpl(MethodImplOptions.NoInlining)]. This keeps the caller's code size small and avoids the overhead of the exception-throwing logic being considered during inlining decisions.

        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
        private static void ThrowInvalidState(CameraState curState, params CameraState[] required) =>
            throw new InvalidOperationException($"The camera is not in a valid state. " +
                $"Current State : { curState }, Valid State : { string.Join(", ", required) }.");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 [AI Review]
Addressed in db34058. Used a fully-qualified attribute name (global::System.Runtime.CompilerServices.MethodImpl) because this file lives in namespace Tizen.Multimedia and the unqualified System.Runtime form collides with the sibling Tizen.System namespace (CS0234).


internal void SetState(CameraState state)
{
_state = state;
Expand Down
Loading