-
Notifications
You must be signed in to change notification settings - Fork 64
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
Added buffer files #101
base: main
Are you sure you want to change the base?
Added buffer files #101
Conversation
}; | ||
} | ||
|
||
#endif // COMPRESSOR_FRONTEND_BUFFER_HPP |
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.
Add empty newline at end of file.
// Dynamic storage performs better as c-style arrays than as vectors | ||
type* m_active_storage; | ||
std::vector<type*> m_dynamic_storages; | ||
type m_static_storage[cStaticByteBuffSize]; |
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.
type m_static_storage[cStaticByteBuffSize]; | |
std::array<type, cStaticByteBuffSize> m_static_storage; |
} | ||
m_dynamic_storages.clear(); | ||
m_active_storage = m_static_storage; | ||
m_curr_storage_size = cStaticByteBuffSize; |
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.
m_curr_storage_size = cStaticByteBuffSize; | |
m_curr_storage_size = m_static_storage.size(); |
// Project Headers | ||
#include "Constants.hpp" | ||
|
||
/** |
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.
- Class header comment should go above the class definition.
- Comment lines should be less than 80 characters.
- This description is vague. You should ideally explain why you would need a static and a dynamic buffer, grouped together in one class.
class Buffer { | ||
public: | ||
// Prevent copying of buffer as this will be really slow | ||
Buffer (Buffer&&) = delete; |
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 you're deleting the move constructor, you should delete the copy constructor as well (see rule of 5).
- Why're you deleting the move constructor?
- The move constructor should come after the constructor.
public: | ||
|
||
/** | ||
* Increment buffer pos, swaps to a dynamic buffer (or doubles its size) if needed |
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.
- Should be in imperative form.
- Swapping to a dynamic buffer seems like an implementation detail (so it shouldn't be in the API header comment).
- It's not really clear to a reader what
pos
is. Perhaps this should be calledadvance_to_next_token
?
|
||
/** | ||
* Resets output buffer | ||
* @return |
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.
No return
(Token*)malloc(2 * m_curr_storage_size * sizeof(Token))); | ||
if (m_dynamic_storages.back() == nullptr) { | ||
SPDLOG_ERROR("Failed to allocate output buffer of size {}.", m_curr_storage_size); | ||
/// TODO: update exception when they're properly |
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.
When they're properly what?
*/ | ||
namespace compressor_frontend { | ||
|
||
class OutputBuffer : public Buffer<Token> { |
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.
OutputTokenBuffer?
} | ||
m_dynamic_storages.clear(); | ||
m_active_storage = m_static_storage; | ||
m_curr_storage_size = cStaticByteBuffSize; |
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.
It's not in this review, but I would suggest changing cStaticByteBuffSize
to be something like cStaticSingleBufferSize
and make it be half of its current value. Then multiply it by 2 wherever necessary.
- Dropping "Byte" is because it's not just used for a byte buffer.
- Dividing it by 2 means we avoid a case where a developer later changes the size to something that's not evenly divisible.
Can we also add some tests, even if they're basic? |
Description
Added 5 new files for buffer classes.