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

Use Qt for directory functions #175

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

Conversation

Cambloid
Copy link

No description provided.

Copy link
Owner

@Garux Garux left a comment

Choose a reason for hiding this comment

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

What are positive effects of this change? I'd prefer to keep internal stuff UI framework agnostic where possible. So std::fs, if refactoring this at all. Currently all path handling is done in ascii char*, so glib functions perform well here w/o extra load and conversions.

Note: entries loading order must be checked for changes if refactoring this.

Makefile Show resolved Hide resolved
libs/os/dir.h Outdated Show resolved Hide resolved
libs/os/dir.h Show resolved Hide resolved
libs/os/dir.cpp Outdated
const char* Directory::read_and_increment(){
if(this->dir) {
QDir* dir_instance = reinterpret_cast<QDir*>(this->dir);
QStringList entryList = dir_instance->entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
Copy link
Owner

Choose a reason for hiding this comment

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

This is srs perf penalty. E.g. with 1k entries in a browsed folder level at least 1M allocations will occur.

Copy link
Author

Choose a reason for hiding this comment

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

changed

libs/os/dir.cpp Outdated
QString file_path = entryList.at(this->entry_idx);
QString file_name = QFileInfo(file_path).fileName();
this->entry_idx++;
return file_name.toStdString().c_str();
Copy link
Owner

Choose a reason for hiding this comment

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

.toLatin1() is more correct for this sort of conversions.
And we are returning pointer to temp local variable here ⚰️

Copy link
Author

Choose a reason for hiding this comment

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

changed

Copy link
Author

Choose a reason for hiding this comment

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

The reason why glib was removed is because qt provides directory management therefore glib seems to be redundant.

Copy link
Author

Choose a reason for hiding this comment

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

I would love to know your take on this, this project already heavily uses qt why not use qt core for internal stuff as well.

Copy link
Owner

Choose a reason for hiding this comment

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

Qt is used almost exclusively for UI.
Ic no positive effects of this change. It's not even removing glib dependency, which is used in other places.
While it adds dependency on big juicy framework, which may be unwelcome in case of some potential porting. Imagine doing Gtk->Qt port if not just UI was dependent on Gtk.
Also performance and behavior compatibility of this change are questionable.

@@ -7,34 +7,28 @@

Directory::Directory(const char* name) {
this->dir = new QDir(name);
QStringList entryList = this->dir->entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
for(int i = 0; i < entryList.size(); i++) {
QString file_path = entryList.at(i);
Copy link
Owner

Choose a reason for hiding this comment

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

This is unnecessary copy. QString is using hashed pool, but it's not free still. Normal practice is taking reference.

for(int i = 0; i < entryList.size(); i++) {
QString file_path = entryList.at(i);
QString file_name = QFileInfo(file_path).fileName();
this->entries.push_back(file_name.toLatin1().data());
Copy link
Owner

Choose a reason for hiding this comment

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

You store pointer to temp string here. Do you even test? This is straightforward crash.

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.

2 participants