Changeset View
Changeset View
Standalone View
Standalone View
src/core/kfileitem.cpp
Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Line(s) | 187 | if (m_url.isLocalFile()) { | |||
---|---|---|---|---|---|
190 | * change into it .. which may not be allowed | 190 | * change into it .. which may not be allowed | ||
191 | * stat("/is/unaccessible") -> rwx------ | 191 | * stat("/is/unaccessible") -> rwx------ | ||
192 | * stat("/is/unaccessible/") -> EPERM H.Z. | 192 | * stat("/is/unaccessible/") -> EPERM H.Z. | ||
193 | * This is the reason for the StripTrailingSlash | 193 | * This is the reason for the StripTrailingSlash | ||
194 | */ | 194 | */ | ||
195 | QT_STATBUF buf; | 195 | QT_STATBUF buf; | ||
196 | const QString path = m_url.adjusted(QUrl::StripTrailingSlash).toLocalFile(); | 196 | const QString path = m_url.adjusted(QUrl::StripTrailingSlash).toLocalFile(); | ||
197 | const QByteArray pathBA = QFile::encodeName(path); | 197 | const QByteArray pathBA = QFile::encodeName(path); | ||
198 | if (QT_LSTAT(pathBA.constData(), &buf) == 0) { | 198 | if (QT_LSTAT(pathBA.constData(), &buf) == 0) { | ||
bruns: m_entry.reserve(9) | |||||
Wouldn't it be better to call m_entry.clear() and m_entry.insert(...) here? For the call from the constructor, m_entry is empty, so you save the std::find_if() in the replace method calls. For any other caller, is there any useful info in m_entry() which is still valid when calling init() again? bruns: Wouldn't it be better to call m_entry.clear() and m_entry.insert(...) here?
For the call from… | |||||
bruns: Ignore this one .. | |||||
In fact, I've tried creating a method to delete in one pass some selected values and then insert again, but it was 10 milliseconds slower than calling replace directly. jtamate: In fact, I've tried creating a method to delete in one pass some selected values and then… | |||||
199 | m_entry.insert(KIO::UDSEntry::UDS_DEVICE_ID, buf.st_dev); | 199 | m_entry.reserve(9); | ||
200 | m_entry.insert(KIO::UDSEntry::UDS_INODE, buf.st_ino); | 200 | m_entry.replace(KIO::UDSEntry::UDS_DEVICE_ID, buf.st_dev); | ||
201 | m_entry.replace(KIO::UDSEntry::UDS_INODE, buf.st_ino); | ||||
201 | 202 | | |||
202 | mode_t mode = buf.st_mode; | 203 | mode_t mode = buf.st_mode; | ||
203 | if ((buf.st_mode & QT_STAT_MASK) == QT_STAT_LNK) { | 204 | if ((buf.st_mode & QT_STAT_MASK) == QT_STAT_LNK) { | ||
204 | m_bLink = true; | 205 | m_bLink = true; | ||
205 | if (QT_STAT(pathBA, &buf) == 0) { | 206 | if (QT_STAT(pathBA, &buf) == 0) { | ||
206 | mode = buf.st_mode; | 207 | mode = buf.st_mode; | ||
207 | } else {// link pointing to nowhere (see FileProtocol::createUDSEntry() in ioslaves/file/file.cpp) | 208 | } else {// link pointing to nowhere (see FileProtocol::createUDSEntry() in ioslaves/file/file.cpp) | ||
208 | mode = (QT_STAT_MASK - 1) | S_IRWXU | S_IRWXG | S_IRWXO; | 209 | mode = (QT_STAT_MASK - 1) | S_IRWXU | S_IRWXG | S_IRWXO; | ||
209 | } | 210 | } | ||
210 | } | 211 | } | ||
211 | m_entry.insert(KIO::UDSEntry::UDS_SIZE, buf.st_size); | 212 | m_entry.replace(KIO::UDSEntry::UDS_SIZE, buf.st_size); | ||
212 | m_entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, buf.st_mode & QT_STAT_MASK); // extract file type | 213 | m_entry.replace(KIO::UDSEntry::UDS_FILE_TYPE, buf.st_mode & QT_STAT_MASK); // extract file type | ||
213 | m_entry.insert(KIO::UDSEntry::UDS_ACCESS, buf.st_mode & 07777); // extract permissions | 214 | m_entry.replace(KIO::UDSEntry::UDS_ACCESS, buf.st_mode & 07777); // extract permissions | ||
214 | m_entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, buf.st_mtime); // TODO: we could use msecs too... | 215 | m_entry.replace(KIO::UDSEntry::UDS_MODIFICATION_TIME, buf.st_mtime); // TODO: we could use msecs too... | ||
215 | m_entry.insert(KIO::UDSEntry::UDS_ACCESS_TIME, buf.st_atime); | 216 | m_entry.replace(KIO::UDSEntry::UDS_ACCESS_TIME, buf.st_atime); | ||
216 | #ifndef Q_OS_WIN | 217 | #ifndef Q_OS_WIN | ||
217 | m_entry.insert(KIO::UDSEntry::UDS_USER, KUser(buf.st_uid).loginName()); | 218 | m_entry.replace(KIO::UDSEntry::UDS_USER, KUser(buf.st_uid).loginName()); | ||
218 | m_entry.insert(KIO::UDSEntry::UDS_GROUP, KUserGroup(buf.st_gid).name()); | 219 | m_entry.replace(KIO::UDSEntry::UDS_GROUP, KUserGroup(buf.st_gid).name()); | ||
219 | #endif | 220 | #endif | ||
220 | 221 | | |||
221 | // TODO: these can be removed, we can use UDS_FILE_TYPE and UDS_ACCESS everywhere | 222 | // TODO: these can be removed, we can use UDS_FILE_TYPE and UDS_ACCESS everywhere | ||
222 | if (m_fileMode == KFileItem::Unknown) { | 223 | if (m_fileMode == KFileItem::Unknown) { | ||
223 | m_fileMode = mode & QT_STAT_MASK; // extract file type | 224 | m_fileMode = mode & QT_STAT_MASK; // extract file type | ||
224 | } | 225 | } | ||
225 | if (m_permissions == KFileItem::Unknown) { | 226 | if (m_permissions == KFileItem::Unknown) { | ||
226 | m_permissions = mode & 07777; // extract permissions | 227 | m_permissions = mode & 07777; // extract permissions | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 293 | { | |||
298 | case KFileItem::CreationTime: | 299 | case KFileItem::CreationTime: | ||
299 | return KIO::UDSEntry::UDS_CREATION_TIME; | 300 | return KIO::UDSEntry::UDS_CREATION_TIME; | ||
300 | } | 301 | } | ||
301 | return 0; | 302 | return 0; | ||
302 | } | 303 | } | ||
303 | 304 | | |||
304 | void KFileItemPrivate::setTime(KFileItem::FileTimes mappedWhich, uint time_t_val) const | 305 | void KFileItemPrivate::setTime(KFileItem::FileTimes mappedWhich, uint time_t_val) const | ||
305 | { | 306 | { | ||
306 | m_entry.insert(udsFieldForTime(mappedWhich), time_t_val); | 307 | m_entry.replace(udsFieldForTime(mappedWhich), time_t_val); | ||
307 | } | 308 | } | ||
308 | 309 | | |||
309 | void KFileItemPrivate::setTime(KFileItem::FileTimes mappedWhich, const QDateTime &val) const | 310 | void KFileItemPrivate::setTime(KFileItem::FileTimes mappedWhich, const QDateTime &val) const | ||
310 | { | 311 | { | ||
311 | const QDateTime dt = val.toLocalTime(); // #160979 | 312 | const QDateTime dt = val.toLocalTime(); // #160979 | ||
312 | setTime(mappedWhich, dt.toTime_t()); | 313 | setTime(mappedWhich, dt.toTime_t()); | ||
313 | } | 314 | } | ||
314 | 315 | | |||
▲ Show 20 Lines • Show All 227 Lines • ▼ Show 20 Line(s) | |||||
542 | 543 | | |||
543 | void KFileItem::setLocalPath(const QString &path) | 544 | void KFileItem::setLocalPath(const QString &path) | ||
544 | { | 545 | { | ||
545 | if (!d) { | 546 | if (!d) { | ||
546 | qCWarning(KIO_CORE) << "null item"; | 547 | qCWarning(KIO_CORE) << "null item"; | ||
547 | return; | 548 | return; | ||
548 | } | 549 | } | ||
549 | 550 | | |||
550 | d->m_entry.insert(KIO::UDSEntry::UDS_LOCAL_PATH, path); | 551 | d->m_entry.replace(KIO::UDSEntry::UDS_LOCAL_PATH, path); | ||
551 | } | 552 | } | ||
552 | 553 | | |||
553 | void KFileItem::setName(const QString &name) | 554 | void KFileItem::setName(const QString &name) | ||
554 | { | 555 | { | ||
555 | if (!d) { | 556 | if (!d) { | ||
556 | qCWarning(KIO_CORE) << "null item"; | 557 | qCWarning(KIO_CORE) << "null item"; | ||
557 | return; | 558 | return; | ||
558 | } | 559 | } | ||
559 | 560 | | |||
560 | d->m_strName = name; | 561 | d->m_strName = name; | ||
561 | if (!d->m_strName.isEmpty()) { | 562 | if (!d->m_strName.isEmpty()) { | ||
562 | d->m_strText = KIO::decodeFileName(d->m_strName); | 563 | d->m_strText = KIO::decodeFileName(d->m_strName); | ||
563 | } | 564 | } | ||
564 | if (d->m_entry.contains(KIO::UDSEntry::UDS_NAME)) { | 565 | if (d->m_entry.contains(KIO::UDSEntry::UDS_NAME)) { | ||
565 | d->m_entry.insert(KIO::UDSEntry::UDS_NAME, d->m_strName); // #195385 | 566 | d->m_entry.replace(KIO::UDSEntry::UDS_NAME, d->m_strName); // #195385 | ||
566 | } | 567 | } | ||
567 | 568 | | |||
568 | } | 569 | } | ||
569 | 570 | | |||
570 | QString KFileItem::linkDest() const | 571 | QString KFileItem::linkDest() const | ||
571 | { | 572 | { | ||
572 | if (!d) { | 573 | if (!d) { | ||
573 | return QString(); | 574 | return QString(); | ||
▲ Show 20 Lines • Show All 1006 Lines • Show Last 20 Lines |
m_entry.reserve(9)