Skip to content
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

Do not push 'read' operation on Video constructor #120

Merged
merged 2 commits into from
Aug 5, 2019

Conversation

mahircg
Copy link
Contributor

@mahircg mahircg commented Jul 30, 2019

Currently, in some of the constructors of Video class, a 'read' operation is
enqueued into the operation queue to ensure that the video is read before
any other operation is performed. This, however, forces a read operation on
on a video object even if there are no operations to apply (i.e.
_operations is empty).

This patch defers read operations until they are absolutely necessary.
This is done by storing the operations in a linked list (rather than a
vector), and adding a read operation to the head of the queue before
perform_operations() invokes each operation in the queue.

Signed-off-by: mahircg [email protected]

@@ -523,6 +524,14 @@ namespace VCL {
*/
void read(const std::string &video_id );
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove this function in another commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, will do.

src/vcl/Video.cc Outdated
if (!_video_id.empty() && !is_read())
_operations.push_front(std::make_shared<Read>());
}
for (auto op : _operations) {
Copy link
Contributor

Choose a reason for hiding this comment

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

will auto& also work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that should work fine.

Choose a reason for hiding this comment

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

const auto & ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Last patch iterates through the elements that way.

src/vcl/Video.cc Outdated
bool is_empty = _operations.empty();
auto first_op = !is_empty ? _operations.front() : NULL;
if (is_empty || (first_op && first_op->get_type() != READ)) {
if (!_video_id.empty() && !is_read())
Copy link
Contributor

Choose a reason for hiding this comment

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

if !_video_id.empty(), we should throw

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the case where the execution reaches this function through the default constructor, which I believe should never happen (hence 'throw').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose that condition would be if (video_id.empty()) { throw ... } though.

src/vcl/Video.cc Outdated
std::shared_ptr<Operation> op = _operations[x];
bool is_empty = _operations.empty();
auto first_op = !is_empty ? _operations.front() : NULL;
if (is_empty || (first_op && first_op->get_type() != READ)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be simplified as (it is safe as .empty is evaluated first):
if ( (_operations.empty() || _operations.front()->get_type() != READ) && !is_read()) ) {
if (!_video_id.empty())
throw
_operations.push_front(std::make_shared());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, looks way more clean.

@mahircg mahircg force-pushed the remove-forced-read branch from 3185203 to 5c6bad9 Compare July 30, 2019 17:27
luisremis
luisremis previously approved these changes Jul 30, 2019
Copy link
Contributor

@luisremis luisremis left a comment

Choose a reason for hiding this comment

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

lgtm! I would be nice to split the commit with the test.

@mahircg
Copy link
Contributor Author

mahircg commented Jul 30, 2019

I'll separate the UT and will add the patch to remove the 'read'.

* Stores a Read Operation in the list of operations
* to perform
* Checks whether the video pointed by the current video_id has
* has already been read.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

duplicate \has\

mahircg added 2 commits August 1, 2019 22:38
Currently, in some of the constructors of Video class, a 'read' operation is
enqueued into the operation queue to ensure that the video is read before
any other operation is performed. This, however, forces a read operation on
on a video object even if there are no operations to apply (i.e.
_operations is empty).

This patch defers read operations until they are absolutely necessary.
This is done by storing the operations in a linked list (rather than a
vector), and adding a read operation to the head of the queue before
perform_operations() invokes each operation in the queue.

Signed-off-by: mahircg <[email protected]>
read() method is in protected scope, and cannot be called from any of
the clients. Since read() function calls were removed in a prior commit,
there's no need to keep the function.

Signed-off-by: mahircg <[email protected]>
@mahircg mahircg force-pushed the remove-forced-read branch from 65100c9 to a490996 Compare August 1, 2019 20:39
Copy link
Contributor

@luisremis luisremis left a comment

Choose a reason for hiding this comment

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

lgtm!

src/vcl/Video.cc Outdated Show resolved Hide resolved
src/vcl/Video.cc Outdated Show resolved Hide resolved
@luisremis luisremis merged commit 08a6981 into develop Aug 5, 2019
@luisremis luisremis deleted the remove-forced-read branch April 21, 2020 19:56
cwlacewe added a commit to cwlacewe/vdms that referenced this pull request May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants