Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Reverse Order on QStringList slow...?

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Reverse Order on QStringList slow...?

    I must delete file and collection (folder on remote server Webdav) i read file and dir on separate list
    from level 0 to infinity down ...
    Now to begin to delete file and Dir i must beginn from last level down
    and i reverse the list so.....


    Qt Code:
    1. QStringList ReverseList( QStringList xx )
    2.  
    3. {
    4.  
    5. if (xx.size() == 0) {
    6.  
    7. return xx;
    8.  
    9. }
    10.  
    11. QStringList newreversed;
    12.  
    13. newreversed.clear();
    14.  
    15. bool walking = true;
    16.  
    17. int o = xx.size();
    18.  
    19. for (;walking;) {
    20.  
    21. o--; /* size 1 goto 0 ; size 2 start on 1 end on 0 */
    22.  
    23. newreversed.append(xx.at(o));
    24.  
    25. if (o == 0) {
    26.  
    27. walking = false;
    28.  
    29. }
    30.  
    31. }
    32.  
    33. return newreversed;
    34.  
    35. }
    To copy to clipboard, switch view to plain text mode 

    I suppose and i see now is very slow the action why?
    is ther a other method to reverse a list?...

    If You have a remote webdav dir ..... can you test the application?
    curl -O http://ppk.ciz.ch/qt_c++/webdavdir.tar.gz
    tar -zxvf w* && cd w*
    qmake a.pro && make
    ./webdav

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by patrik08 View Post
    is ther a other method to reverse a list?...
    Qt Code:
    1. #include <algorithm>
    2. std::reverse(xx.begin(), xx.end());
    To copy to clipboard, switch view to plain text mode 

    But you don't have to reverse the list to iterate it in reverse order... QList has an index based way of accessing items, so you can just make a for loop:
    Qt Code:
    1. for(int i=xx.size()-1; i>=0;i--){
    2. doSomething(xx.at(i));
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to wysota for this useful post:

    patrik08 (20th February 2007)

  4. #3
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by patrik08 View Post
    I must delete file and collection (folder on remote server Webdav) i read file and dir on separate list
    from level 0 to infinity down ...
    Now to begin to delete file and Dir i must beginn from last level down
    and i reverse the list so.....
    Are you sure that reversing the list is your problem? (Beside that you do not even need it as wysota mentioned ;-)

    I just wrote a (completly unscientific but good enough to get an idea) benchmark for it...and it does not seem to take that much time.

    Here is my test prog (with an other implementation of reverse that does only take about half of the time):
    Qt Code:
    1. #include <QtCore>
    2.  
    3.  
    4. static inline QStringList oldReverseList(const QStringList &xx)
    5. {
    6. if (xx.size() == 0) {
    7. return xx;
    8. }
    9.  
    10. QStringList newreversed;
    11. newreversed.clear();
    12.  
    13. bool walking = true;
    14.  
    15. int o = xx.size();
    16. for (;walking;) {
    17. o--; /* size 1 goto 0 ; size 2 start on 1 end on 0 */
    18. newreversed.append(xx.at(o));
    19. if (o == 0) {
    20. walking = false;
    21. }
    22. }
    23. return newreversed;
    24. }
    25.  
    26. static inline QStringList newReverseList(const QStringList &list)
    27. {
    28. if (list.isEmpty()) {
    29. return QStringList();
    30. }
    31.  
    32. QStringList reversedList = list;
    33. const int listSize = list.size();
    34. const int maxSwap = list.size() / 2;
    35. for (int i = 0; i < maxSwap; ++i) {
    36. qSwap(reversedList[i], reversedList[listSize - 1 -i]);
    37. }
    38.  
    39. return reversedList;
    40. }
    41.  
    42. int main(int argc, char* argv[])
    43. {
    44. Q_UNUSED(argc);
    45. Q_UNUSED(argv);
    46.  
    47. QStringList testList;
    48. for (int i = 1; i < 100; ++i) {
    49. testList << QString::number(i);
    50. }
    51.  
    52. const int iterations = 1000000;
    53. {
    54. QDateTime start = QDateTime::currentDateTime();
    55. for (int j = 1; j < iterations; ++j) {
    56. QStringList reversedList = oldReverseList(testList);
    57. if (testList != oldReverseList(reversedList)) {
    58. qFatal("reverseList is broken");
    59. }
    60. }
    61. QDateTime stop = QDateTime::currentDateTime();
    62. qDebug() << iterations * 2 << "iterations of oldReverseList in" << start.secsTo(stop) << "seconds ";
    63. }
    64. {
    65. QDateTime start = QDateTime::currentDateTime();
    66. for (int j = 1; j < iterations; ++j) {
    67. QStringList reversedList = newReverseList(testList);
    68. if (testList != newReverseList(reversedList)) {
    69. qFatal("reverseList is broken");
    70. }
    71. }
    72. QDateTime stop = QDateTime::currentDateTime();
    73. qDebug() << iterations * 2 << "iterations of newReverseList in" << start.secsTo(stop) "seconds";
    74. }
    75. return 0;
    76. }
    To copy to clipboard, switch view to plain text mode 

    The results that I got were:
    2000000 iterations of oldReverseList in 13 seconds
    2000000 iterations of newReverseList in 7 seconds

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reverse Order on QStringList slow...?

    The results are obvious and the benchmark is not needed If you do half the amount of iterations, you'll get half amount of effort to complete the task I'm pretty certain std::reverse uses the same algorithm your newReverse does (as there is no "temporary" or "second" list so it has to store objects in the list itself and the easiest way to do that is to just swap the items).

    Anyway I think the problem is not in the list (like already mentioned) but on the deleting algorithm... Why do you need those two lists (dirs/files)? Can't you do a recursive delete of the root directory?

    Pseudocode follows:
    Qt Code:
    1. bool deleteDir(const QString &path){
    2. bool good = true;
    3. QStringList entries = children(path);
    4. foreach(QString entry, entries){
    5. if(isFile(entry))
    6. good = deleteFile(path+entry);
    7. else if(isDir(entry))
    8. good = deleteDir(path+entry); // recursive call here
    9. if(!good)
    10. return false; // bail out on error
    11. }
    12. return deleteSelf(path);
    13. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by wysota View Post
    The results are obvious and the benchmark is not needed If you do half the amount of iterations, you'll get half amount of effort to complete the task I'm pretty certain std::reverse uses the same algorithm your newReverse does (as there is no "temporary" or "second" list so it has to store objects in the list itself and the easiest way to do that is to just swap the items).
    Actually they are not 100% obvious, depending of you viewpoint. I am thinking about memory allocation problems.
    When you have a QList and fill them one by one, you might get problems with reallocation, as the QList needs more memory.

    I first thought about experimenting with that, using reserve(as in QVector::reserve()) ... until I noticed that there is not such a thing in QList ;-)

    Thus, copy and detach :-)


    qSwap has another (very slight) advantage over using the std algorithms (at least when using with implicitly shared Qt types, and types sufficiently declared using Q_DECLARE_TYPEINFO) as it does some bad magic if the type is only the size of a pointer. This saves some atomic operations compared to doing it via three way operator=().

    TIP: Qt has a nice collection of algorithms for containers :-)


    But I guess this transgresses into the realm of the very off topic ;-)

    [And: these kind of optimizations should only be taken out of the safe when everything else is failing...which it they do not at this point ;-) ]
    Last edited by camel; 20th February 2007 at 14:02. Reason: added TypeInfo bit, that is important for qSwap

  7. #6
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by wysota View Post
    I'm pretty certain std::reverse uses the same algorithm your newReverse does
    Actually I just added a stdReverseList to the mix
    Qt Code:
    1. static inline QStringList stdReverseList(const QStringList &list)
    2. {
    3. QStringList reversedList = list;
    4. std::reverse(reversedList.begin(), reversedList.end());
    5. return reversedList;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Result:
    2000000 iterations of oldReverseList in 13 seconds
    2000000 iterations of newReverseList in 7 seconds
    2000000 iterations of stdReverseList in 14 seconds
    My totaly unscientific guess to explain the result, would be that access via the iterators (as needed by std::reverse) is slower than access via operator[]...

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by camel View Post
    When you have a QList and fill them one by one, you might get problems with reallocation, as the QList needs more memory.
    Yes, but the list doesn't allocate one by one, it does a preallocation.

    I first thought about experimenting with that, using reserve(as in QVector::reserve()) ... until I noticed that there is not such a thing in QList ;-)
    It wouldn't have much sense. QVector expands in one direction (items are "appended" to the end), whereas QList can grow in two directions (items can be "appended" or "prepended"). Reserve would not make much sense then, you'd need two methods instead ("reserveAtEnd" and "reserveAtFront"). But you can subsitute QStringList with QVector<String> without any performance loss as in this situation items are only added to the end, not anywhere inbetween or in front.


    qSwap has another (very slight) advantage over using the std algorithms (at least when using with implicitly shared Qt types) as it does some bad magic if the type is only the size of a pointer. This saves some atomic operations compared to doing it via three way operator=().
    Yes, it can actually exchange the values, but the value needs to be memmovable.

    About the speed of std::reverse - the use of iterators should slow QList down that much. I'm convinced that the iterator in QList is not much more than item index, so access to an element should always be O(1). Operator= for QList has the same features qSwap has and additionally QString is pretty fast on its own, so that also should have such a big influence. My guess is that std::reverse is simply slow

    Actually I just checked my implementation of std::reverse:

    Qt Code:
    1. {
    2. while (true)
    3. if (__first == __last || __first == --__last)
    4. return;
    5. else
    6. {
    7. std::iter_swap(__first, __last);
    8. ++__first;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    It uses the exact same algorithm your fast implementation uses. So the slowdown has to be either in QList itself or in std::iter_swap.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reverse Order on QStringList slow...?

    I made a test using a QVector based implementation of the oldReverseList function that preallocates all the needed memory in the constructor.
    Qt Code:
    1. 2000000 iterations of oldReverseList in 18 seconds
    2. 2000000 iterations of oldReverseList2 in 15 seconds
    To copy to clipboard, switch view to plain text mode 
    It's slightly faster, but I wouldn't call it a big difference.

    The implementation:
    Qt Code:
    1. static inline QVector<QString> oldReverseList2(const QStringList &xx)
    2. {
    3. if (xx.size() == 0) {
    4. return QVector<QString>();
    5. }
    6. QVector<QString> newreversed(xx.size());
    7. int s = xx.size();
    8. int li = 0;
    9. for(int i=s-1; i>=0;i--) {
    10. newreversed[li++] =xx.at(i);
    11. }
    12. return newreversed;
    13. }
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by wysota View Post
    So the slowdown has to be either in QList itself or in std::iter_swap.

    We have a winner ;-)

    I added the (not very beautifull) reimplementation of std::reverse using qSwap:
    Qt Code:
    1. static inline QStringList std2ReverseList(const QStringList &list)
    2. {
    3. QStringList reversedList = list;
    4. QStringList::iterator __first = reversedList.begin();
    5. QStringList::iterator __last = reversedList.end();
    6. {
    7. while (true)
    8. if (__first == __last || __first == --__last)
    9. return reversedList;
    10. else
    11. {
    12. qSwap(*__first, *__last);
    13. ++__first;
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 


    The result:
    2000000 iterations of oldReverseList in 14 seconds
    2000000 iterations of newReverseList in 8 seconds
    2000000 iterations of stdReverseList in 14 seconds
    2000000 iterations of std2ReverseList in 6 seconds
    This means this is the (in the moment) speediest implementation, and the problem is in std::iter_swap

    ;-)

  11. #10
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    the fasted solution is to read list reverse .....

    and QStringList::appends(QStringList other list) not exist.....


    Qt Code:
    1. void Gui_Remove::WakeUpsFile()
    2. {
    3. CodaonDelete.clear(); /* container file and dir */
    4. passaggiwake++;
    5. //////////qDebug() << "####LISTTOBE REMOVE ->" << passaggiwake << "-" << startpath;
    6.  
    7. if ( passaggiwake >= 2) {
    8. return; /* break if like read a 2° time and delete not exist file */
    9. }
    10.  
    11. QStringList RFile = ReverseList(Del_File); /* reverse list from file delete file on top */
    12.  
    13. for (int i = 0; i < RFile.size(); ++i) { /* to save time only read reverse the list */
    14. //////////qDebug() << "###file del -> " << RFile.at(i);
    15. CodaonDelete.append(RFile.at(i));
    16. }
    17.  
    18. QStringList RDir = ReverseList(Del_Dir); /* reverse list from dir delete dir on last action */
    19.  
    20. for (int i = 0; i < RDir.size(); ++i) {
    21. //////////qDebug() << "###dir del -> " << RDir.at(i);
    22. CodaonDelete.append(RDir.at(i));
    23. }
    24.  
    25. Del_File.clear();
    26. Del_Dir.clear();
    27. Del_Work_Grep.clear();
    28.  
    29. if (CodaonDelete.size() > 0) {
    30. CodaRemove(0);
    31. }
    32. }
    33.  
    34.  
    35. void Gui_Remove::CodaRemove( int now ) /* loop all dir and file list send to class delete */
    36. {
    37.  
    38. if (aborter) { /* button abort delete */
    39. return;
    40. }
    41.  
    42. int bigmap = CodaonDelete.size();
    43. if (bigmap == 0) {
    44. CodaonDelete.clear(); /* sure */
    45. LastRemove(); /* remove the last on top path */
    46. return;
    47. }
    48.  
    49. if (now >= bigmap) {
    50. CodaonDelete.clear();
    51. LastRemove(); /* remove the last on top path */
    52. return;
    53. }
    54. for (int i = 0; i < CodaonDelete.size(); ++i) {
    55. if (now == i) {
    56. QString anextpath = RealRemotePath(CodaonDelete.at(i));
    57. if (anextpath.size() > 0) {
    58.  
    59. label->setText(tr("Pending operation on: %1").arg(RealRemotePath(startpath)));
    60. label_2->setText(tr("Remove wait: %1").arg(anextpath));
    61.  
    62.  
    63. DavDelete *lismix = new DavDelete(dbdav,anextpath); /* file or dir */
    64. lismix->SetPosition(now);
    65. connect(lismix, SIGNAL(WarningMsg(QString)), this, SLOT(ShowMessageWarning(QString))); /* abort the loop */
    66. connect(lismix, SIGNAL(ConChain(int)), this, SLOT(CodaRemove(int))); /* continue delete from path down to up */
    67. } else {
    68. CodaRemove(now + 1);
    69. }
    70. return;
    71. }
    72. }
    73. }
    To copy to clipboard, switch view to plain text mode 

  12. #11
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Just to post my latest findings (of how you can speed up standard algorithms when you work with Qt types)

    I simply added the following code:
    Qt Code:
    1. static inline void swap(QString& a, QString& b)
    2. {
    3. qSwap(a,b);
    4. }
    To copy to clipboard, switch view to plain text mode 

    That changed the result to:
    2000000 iterations of oldReverseList in 13 seconds
    2000000 iterations of newReverseList in 7 seconds
    2000000 iterations of stdReverseList in 7 seconds
    2000000 iterations of std2ReverseList in 6 seconds
    That means you get very easily a great(*) speedup because the STL can now use the optimizations used in qSwap. (Still not as fast as the overall winner here, but the absolute winner in the work/result ratio category :-)

    (*): "great" of course only if you do 2000000 million iterations of a reverse list algorithm...which you probably do not do ;-)
    but its probably a thing to keep in mind if you find the std algorithms taking too long for your taste :-)
    Last edited by camel; 20th February 2007 at 15:01.

  13. #12
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by patrik08 View Post
    the fasted solution is to read list reverse .....
    Well yeah...but it's not as much fun ;-)


    Quote Originally Posted by patrik08 View Post
    and QStringList::appends(QStringList other list) not exist.....
    Use operator+=

    Looking at your code...have you thought about using a QStack?
    you just QStack::push() whatever you find you need to delete onto it, and when you want to do it you simple QStack::pop() the contents of the stack until it is empty....
    Last edited by camel; 20th February 2007 at 15:26.

  14. #13
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Doing a delete with a stack (pseudo-code)
    Qt Code:
    1. bool recursiveDeleteDir(const QString &path){
    2. QStack<QString> currentPathStack;
    3. QStack<QString> deletablePathStack;
    4. QStringList deletableFileList;
    5.  
    6. currentPathStack.push(path);
    7. while (!currentPathStack.isEmpty()) {
    8. QString currentPath = currentPathStack.pop();
    9. if (!isDeletableDir(currentPath))
    10. return false;
    11.  
    12. QStringList entries = children(currentPath);
    13. foreach(QString entry, entries){
    14. if(isFile(entry) && isDeletableFile(entry)) {
    15. deletableFileList << entry;
    16. } else if (isDir(entry)) {
    17. currentPathStack.push(entry);
    18. } else {
    19. return false;
    20. }
    21. }
    22.  
    23. deletablePathStack.push(currentPath);
    24. }
    25. foreach(QString file, deletableFile) {
    26. if (!deleteFile(file)) {
    27. return false; //ERROR: if you get these, your isDeletableFile got a hickup :-/
    28. }
    29. }
    30. while (!deletablePathStack.isEmpty()) {
    31. if (!deleteDir(deletablePathStack.pop())) {
    32. return false; //ERROR: if you get these, your isDeletableDir got a hickup :-/
    33. }
    34. }
    35. return true;
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by camel; 20th February 2007 at 15:38.

  15. #14
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Hmmm... to delete on a local pc a dir recursive .... i not write 200 feet code...

    Qt Code:
    1. /* remove dir recursive */
    2.  
    3. void DownDir_RM(const QString d)
    4.  
    5. {
    6.  
    7. QDir dir(d);
    8.  
    9. if (dir.exists())
    10.  
    11. {
    12.  
    13. const QFileInfoList list = dir.entryInfoList();
    14.  
    15.  
    16. for (int l = 0; l < list.size(); l++)
    17.  
    18. {
    19.  
    20. fi = list.at(l);
    21.  
    22. if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..")
    23.  
    24. DownDir_RM(fi.absoluteFilePath());
    25.  
    26. else if (fi.isFile())
    27.  
    28. {
    29.  
    30. bool ret = qt_unlink(fi.absoluteFilePath());
    31.  
    32. if (!ret) {
    33.  
    34. //////Api_Log("Can't remove: " + fi.absoluteFilePath() + " (write-protect?)");
    35. }
    36.  
    37. }
    38.  
    39.  
    40.  
    41. }
    42.  
    43. dir.rmdir(d);
    44.  
    45.  
    46.  
    47. }
    48.  
    49. }
    To copy to clipboard, switch view to plain text mode 

    My problem is to delete on remote server file and path.....

    to delete dir i and file i have only a class ....

    new QHttp();
    QHttpRequestHeader header("DELETE", pathorfile ,1,1); /* header */

    http://www.webdav.org/specs/rfc2518....ection.8.6.2.1

    Qt Code:
    1. DavDelete *lismix = new DavDelete(dbdav,anextpath);
    2.  
    3. lismix->SetPosition(now);
    4.  
    5. connect(lismix, SIGNAL(WarningMsg(QString)), this, SLOT(ShowMessageWarning(QString)));
    6.  
    7. connect(lismix, SIGNAL(ConChain(int)), this, SLOT(CodaRemove(int)));
    To copy to clipboard, switch view to plain text mode 

    and i have only QStringList from file and Dir or a domdocument like this...
    http://ppk.ciz.ch/qt_c++/davinfo.xml

    to display tree folder like mc gui....


  16. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reverse Order on QStringList slow...?

    I don't see a difference between local and remote delete. The mechanism is the same, you only call a different method to do the actual delete.

  17. #16
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by patrik08 View Post
    new QHttp();
    QHttpRequestHeader header("DELETE", pathorfile ,1,1); /* header */

    http://www.webdav.org/specs/rfc2518....ection.8.6.2.1

    Qt Code:
    1. DavDelete *lismix = new DavDelete(dbdav,anextpath);
    To copy to clipboard, switch view to plain text mode 
    If the first two lines are the contents of your DavDelete, may I propose to you to change the class to take a list of files to delete?

    The problem with your approach is that for every delete a new connection to the webdav server is created, while if you would create multiple requests on a single QHttp the same connection might be used, which is generally faster (even more so if the server and QHttp can do pipelining..but I do not know that).


    (Disregard if you are actually doing this ;-)

    The recursiveDeleteDir approach I posted would work very well for that, since you have, at the end, a list of all paths and files to delete (even in the right order so that you can delete them in a row without error) which you would just have to send to the WebDav server.

    [For this to work efficiently, you must have the isFile, isDir children etc. function only using a local cache of course ;-)]

  18. #17
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Quote Originally Posted by wysota View Post
    I don't see a difference between local and remote delete. The mechanism is the same, you only call a different method to do the actual delete.
    The difference is local remove is a function running on self.... and no signal!!!

    function remove( path ) { /* start on top and work to down */
    make ....
    next level remove(here);
    }

    on Remote each action must start a signal go delete and emitter go back to next file or dir ..... /* from down dir comming up at end remove the top folder... */

    I suppose a multi QThread can handle this .... only one signal to QHttp -> 50 file and dir can delete a dir recursive musch faster.... but a clean example from QThread in to wiki as a multiple action i dont found .... only print A or B sample... to console .... same as the QT4 book from Mister Blanchette and QThread stay a mistery long long time....

  19. #18
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    Qt Code:
    1. static inline int addDeleteRequest(QHttp *http, const QString& name)
    2. {
    3. return http->request(QHttpRequestHeader("DELETE", name ,1,1));
    4. }
    5.  
    6. bool recursiveDeleteDir(const QString &path){
    7. QStack<QString> currentPathStack;
    8. QStack<QString> deletablePathStack;
    9. QStringList deletableFileList;
    10.  
    11. currentPathStack.push(path);
    12. while (!currentPathStack.isEmpty()) {
    13. QString currentPath = currentPathStack.pop();
    14. if (!isDeletableDir(currentPath))
    15. return false;
    16.  
    17. QStringList entries = children(currentPath);
    18. foreach(QString entry, entries){
    19. if(isFile(entry) && isDeletableFile(entry)) {
    20. deletableFileList << entry;
    21. } else if (isDir(entry)) {
    22. currentPathStack.push(entry);
    23. } else {
    24. return false;
    25. }
    26. }
    27.  
    28. deletablePathStack.push(currentPath);
    29. }
    30.  
    31. QHttp *deleterHttp = new QHttp;
    32. // CONNECT deleterHttp HERE
    33. foreach(QString file, deletableFile) {
    34. addDeleteRequest(deleterHttp, file);
    35. }
    36. while (!deletablePathStack.isEmpty()) {
    37. addDeleteRequest(deleterHttp, deletablePathStack.pop());
    38. }
    39. QObject::connect(deleterHttp, SIGNAL(done(bool), deleterHttp, SLOT(deleteLater()));
    40. return true;
    41. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by camel; 20th February 2007 at 17:06.

  20. The following user says thank you to camel for this useful post:

    patrik08 (20th February 2007)

  21. #19
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reverse Order on QStringList slow...?

    I Like Test now "QStack<QString> currentFile;" to download/upload ( rsync like ) a remote dir recursive .... from a remote webdav server .... on Webdav exist a
    <lp1:getetag>"bcd40-8ae-cf1a0340"</lp1:getetag> a md5 like param ....
    i must only discover a way to save this getetag (filename;getetag;lastmodtime) local in to dir from file .... and remove local the getetag string if a file is updated local to become upload true...
    if the remote getetag & the local getetag is same file is sincro true (same version) ... & if a local getetag exist and online getetag is different must download the new version... && update this getetag local....

    http://www.webdav.org/specs/rfc2518....OPERTY_getetag

  22. #20
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default RSync-clone via WebDav - Possible Approaches

    I am truly sorry, but I have sadly no idea what the problem is you are trying to express.

    My Guess is you are:
    • Trying to create rsync like functionality on top of webdav
    • Trying to use the entity tags as a way to see if a file has changed?


    Simplest way:
    Ignore the entity tag, and only use the last modified date (compare the one from the webdav with the one locally, taking into account the different times of the computers).

    Harder way:
    Store the entity tag of a file together with the lastmodified time of the file(when you knew that the file was identical to the one on the server) and a md5/sha1 sum of the file.

    When you want to check for equality server/local
    • If the tag you stored is equal to the one the server tells you, check if the file still has the same modified date and if: great they are equal.
    • If the tags are equal and the modified date of the file and the stored one are different, compare the stored md5/sha1 sum to the real one of the file. If they are equal...well we do not care if it was "modified" but not changed. => files are equal
    • If tags are equal and the modified since and the md5/sha1 sum is different => local file has changed
    • If the tag from the server differs from the stored tag, you would update it. But you might still want to check if the file has changed locally...and if, you have a very nice conflict...



    Why do you have to do it like this?
    You have no guarantee that anyone who modifies your files will delete the entity tag you stored for it....


    How to store?
    Probably easiest way is a very simple sqlite database using the QSql classes.
    Or you could create an xml file somewhere with that data...or use qsettings or.....


    EDIT: This really gets off-topic if you look at the post-title...;-)
    Last edited by camel; 20th February 2007 at 18:16.

Similar Threads

  1. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 17:01
  2. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 20:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.