Skip to content

Refactor cycle breaking (visited tracking) in SubresourceOperationFactory #1279

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

Conversation

teohhanhui
Copy link
Contributor

…tory

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

Refactor with visited tracking logic which is much easier to follow.

@teohhanhui
Copy link
Contributor Author

PHPStan failure should be addressed in a separate PR.


$this->computeSubresourceOperations($subresourceClass, $tree, $rootResourceClass, $operation, $visiting);
$this->computeSubresourceOperations($subresourceClass, $tree, $rootResourceClass, $operation, array_merge($visited, [$visiting]));
Copy link
Member

Choose a reason for hiding this comment

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

$visited[] = $visiting;

$this->computeSubresourceOperations(..., $visited);

Is it not better for performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that would give the wrong result. We could of course use another variable.

Copy link
Member

Choose a reason for hiding this comment

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

Hum, I think I missed something here... Why is the result wrong? It's not an associative array here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The result would be wrong because we have a loop, if we modify the $visited array in place it'd affect the other properties.

Copy link
Member

Choose a reason for hiding this comment

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

Oh sorry, I missed the loop! BTW it's better like this with an associative array! 👍

@teohhanhui teohhanhui force-pushed the refactor-subresource-cycle-breaking branch from 9a8de56 to f6fc45d Compare July 24, 2017 09:25
@soyuka
Copy link
Member

soyuka commented Jul 24, 2017

Merged in #1283 Thanks @teohhanhui

@soyuka soyuka closed this Jul 24, 2017
@teohhanhui teohhanhui deleted the refactor-subresource-cycle-breaking branch July 25, 2017 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants