8000 SeekHandler: Some janitoring by notspiff · Pull Request #26794 · xbmc/xbmc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

SeekHandler: Some janitoring #26794

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

notspiff
Copy link
Contributor

Description

Modernization and simplification of some SeekHandler code

Motivation and context

More modern, more good

How has this been tested?

It builds

What is the effect on users?

None

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • Student submission (PR was done for educational purposes and will be treated as such)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@notspiff notspiff added this to the Piers 22.0 Alpha 1 milestone May 22, 2025
@notspiff notspiff added Type: Improvement non-breaking change which improves existing functionality v22 Piers labels May 22, 2025
@notspiff notspiff force-pushed the seekhandler_janitoring branch 3 times, most recently from c1ef86b to a972e76 Compare May 22, 2025 20:54
@garbear garbear requested a review from Copilot May 23, 2025 04:52
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Modernizes and simplifies the SeekHandler implementation by adopting modern C++ constructs and removing redundant code.

  • Replaces manual container insertions and loops with emplace, std::ranges::for_each, std::shift_left, and std::accumulate
  • Converts C-style arrays and raw pointers to std::array and nullptr, and adds const qualifiers
  • Removes explicit destructor and cleans up includes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
xbmc/SeekHandler.h Swapped raw array for std::array, default-initialized members, removed destructor declaration, updated includes
xbmc/SeekHandler.cpp Replaced manual clears and inserts with emplace, modernized loops with range algorithms, improved const usage
Comments suppressed due to low confidence (1)

xbmc/SeekHandler.cpp:422

  • [nitpick] Consider adding unit tests for the time code rotation (ChangeTimeCode) and parsing logic (GetTimeCodeSeconds) to catch regressions introduced by the switch to std::shift_left and std::accumulate.
if (m_timeCodePosition > 0)

for (int i = 0; i < m_timeCodePosition; i++)
tot = tot * 10 + m_timeCodeStamp[i];
int tot =
std::accumulate(m_timeCodeStamp.begin(), m_timeCodeStamp.end(), 0,
Copy link
Preview
Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

The accumulation iterates over all 6 slots (including unfilled zeros), producing incorrect values when fewer than 6 digits have been entered. Limit the range to the first m_timeCodePosition elements (e.g. begin() to begin() + m_timeCodePosition).

Suggested change
std::accumulate(m_timeCodeStamp.begin(), m_timeCodeStamp.end(), 0,
std::accumulate(m_timeCodeStamp.begin(), m_timeCodeStamp.begin() + m_timeCodePosition, 0,

Copilot uses AI. Check for mistakes.

Comment on lines 58 to 75
10000
std::ranges::for_each(seekTypeSettingMap,
[&settings, &forwardSteps = m_forwardSeekSteps,
&backwardSteps = m_backwardSeekSteps](const auto& it)
{
auto& forward = forwardSteps[it.first];
auto& backward = backwardSteps[it.first];

std::ranges::for_each(settings->GetList(it.second),
[&backward, &forward](const auto& seekStep)
{
const int stepSeconds =
static_cast<int>(seekStep.asInteger());
if (stepSeconds < 0)
backward.insert(backward.begin(), stepSeconds);
else
forward.push_back(stepSeconds);
});
});
Copy link
Preview
Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

[nitpick] This nested lambda structure with an ambiguously named parameter (it) and deep nesting hurts readability. Consider using a simple range-based for loop or renaming the lambda parameter to something more descriptive (e.g. entry).

Copilot uses AI. Check for mistakes.

@notspiff notspiff force-pushed the seekhandler_janitoring branch from a972e76 to a9b38db Compare May 23, 2025 14:01
@garbear garbear requested a review from Copilot May 24, 2025 00:06
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modernizes and simplifies the SeekHandler code by leveraging modern C++ features. Key changes include:

  • Replacing raw arrays with std::array and providing default initializations.
  • Refactoring loops with C++20 algorithms like std::ranges::for_each and std::shift_left.
  • Improving const correctness and updating legacy pointer comparisons.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
xbmc/SeekHandler.h Uses std::array for the time code stamps and removes unnecessary code
xbmc/SeekHandler.cpp Employs modern iteration and accumulation techniques, and updates error comparisons
Comments suppressed due to low confidence (1)

xbmc/SeekHandler.cpp:58

  • Verify that the use of C++20 ranges, specifically std::ranges::for_each, aligns with the project's minimum C++ standard requirements.
std::ranges::for_each(seekTypeSettingMap, [&settings, &forwardSteps = m_forwardSeekSteps, &backwardSteps = m_backwardSeekSteps](const auto& seekDef) {

@@ -418,8 +409,7 @@ void CSeekHandler::ChangeTimeCode(int remote)
else
{
// rotate around
for (int i = 0; i < 5; i++)
m_timeCodeStamp[i] = m_timeCodeStamp[i + 1];
std::shift_left(m_timeCodeStamp.begin(), m_timeCodeStamp.end(), 1);
Copy link
Preview
Copilot AI May 24, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a brief comment to explain the use of std::shift_left for rotating the timestamp array, noting its C++20 origin to assist future maintainers.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement non-breaking change which improves existing functionality v22 Piers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0