-
Notifications
You must be signed in to change notification settings - Fork 33
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
Conversation
include/vcl/Video.h
Outdated
@@ -523,6 +524,14 @@ namespace VCL { | |||
*/ | |||
void read(const std::string &video_id ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto & ?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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').
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
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.
3185203
to
5c6bad9
Compare
There was a problem hiding this 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.
I'll separate the UT and will add the patch to remove the 'read'. |
include/vcl/Video.h
Outdated
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate \has\
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]>
65100c9
to
a490996
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
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]