-
Notifications
You must be signed in to change notification settings - Fork 59
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
base: master
Are you sure you want to change the base?
Conversation
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.
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.
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); |
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 is srs perf penalty. E.g. with 1k entries in a browsed folder level at least 1M allocations will occur.
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.
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(); |
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.
.toLatin1() is more correct for this sort of conversions.
And we are returning pointer to temp local variable 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.
changed
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.
The reason why glib was removed is because qt provides directory management therefore glib seems to be redundant.
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 would love to know your take on this, this project already heavily uses qt why not use qt core for internal stuff as well.
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.
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); |
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 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()); |
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.
You store pointer to temp string here. Do you even test? This is straightforward crash.
No description provided.