Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 13th, 2011  |  syntax: Diff  |  size: 3.42 KB  |  views: 105  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2.  
  3. ogoffart@oscar demos]$ ./textedit/textedit
  4. HASH stat: total=1024  dup=678
  5. STRING stat: total=53616  hashed=344
  6. [ogoffart@oscar demos]$ ./textedit/textedit
  7. HASH stat: total=5132  dup=4072
  8. STRING stat: total=101315  hashed=1057
  9. [ogoffart@oscar demos]$ qmlviewer
  10. Qml debugging is enabled. Only use this in a safe environment!
  11. HASH stat: total=5341  dup=3989
  12. STRING stat: total=70257  hashed=1323
  13. [ogoffart@oscar demos]$ qmlviewer
  14. Qml debugging is enabled. Only use this in a safe environment!
  15. HASH stat: total=1691  dup=732
  16. STRING stat: total=14373  hashed=930
  17. [ogoffart@oscar demos]$ ./browser/browser
  18. HASH stat: total=2951  dup=1080
  19. STRING stat: total=111836  hashed=1870
  20.  
  21.  
  22.  
  23.  
  24. diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
  25. index f43e888..bfd34dd 100644
  26. --- a/src/corelib/tools/qhash.cpp
  27. +++ b/src/corelib/tools/qhash.cpp
  28. @@ -94,8 +94,22 @@ uint qHash(const QByteArray &key)
  29.      return hash(reinterpret_cast<const uchar *>(key.constData()), key.size());
  30.  }
  31.  
  32. +
  33. +#include <iostream>
  34. +
  35.  uint qHash(const QString &key)
  36.  {
  37. +    struct Stat {
  38. +        QBasicAtomicInt count;
  39. +//        QBasicAtomicInt simple;
  40. +        QBasicAtomicInt dup;
  41. +        ~Stat() {  std::cout <<"HASH stat: total=" << int(count) << "  dup=" << int(dup) <<   std::endl; }
  42. +    };
  43. +    static Stat s = {0, 0};
  44. +    s.count.ref();
  45. +    if (key.asciicache())
  46. +        s.dup.ref();
  47. +    key.setAsciicache();
  48.      return hash(key.unicode(), key.size());
  49.  }
  50.  
  51. diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
  52. index ee45cfd..71e33e5 100644
  53. --- a/src/corelib/tools/qstring.cpp
  54. +++ b/src/corelib/tools/qstring.cpp
  55. @@ -1219,9 +1219,22 @@ QString::QString(QChar ch)
  56.      \internal
  57.  */
  58.  
  59. +#include <iostream>
  60.  // ### Qt 5: rename freeData() to avoid confusion. See task 197625.
  61.  void QString::free(Data *d)
  62.  {
  63. +
  64. +    struct Stat {
  65. +        QBasicAtomicInt count;
  66. +        //        QBasicAtomicInt simple;
  67. +        QBasicAtomicInt hash;
  68. +        ~Stat() {  std::cout <<"STRING stat: total=" << int(count) << "  hashed=" << int(hash) <<   std::endl; }
  69. +    };
  70. +    static Stat s = {0, 0};
  71. +    s.count.ref();
  72. +    if (d->asciiCache)
  73. +        s.hash.ref();
  74. +    
  75.  #ifdef QT3_SUPPORT
  76.      if (d->asciiCache) {
  77.          Q_ASSERT(asciiCache);
  78. diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
  79. index bf0a0ad..9c82029 100644
  80. --- a/src/corelib/tools/qstring.h
  81. +++ b/src/corelib/tools/qstring.h
  82. @@ -590,6 +590,10 @@ public:
  83.  
  84.      QString(int size, Qt::Initialization);
  85.  
  86. +    bool asciicache() const { return d->asciiCache; }
  87. +    void setAsciicache() const {  const_cast<Data *>(d)->asciiCache = 1; }
  88. +    
  89. +    
  90.  private:
  91.  #if defined(QT_NO_CAST_FROM_ASCII) && !defined(Q_NO_DECLARED_NOT_DEFINED)
  92.      QString &operator+=(const char *s);
  93. @@ -600,6 +604,7 @@ private:
  94.      QString &operator=(const QByteArray &a);
  95.  #endif
  96.  
  97. +
  98.      struct Data {
  99.          QBasicAtomicInt ref;
  100.          int alloc, size;
  101. @@ -712,7 +717,7 @@ inline QChar *QString::data()
  102.  inline const QChar *QString::constData() const
  103.  { return reinterpret_cast<const QChar*>(d->data); }
  104.  inline void QString::detach()
  105. -{ if (d->ref != 1 || d->data != d->array) realloc(); }
  106. +{ if (d->ref != 1 || d->data != d->array) realloc(); else if (d->ref==1) d->asciiCache = 0; }
  107.  inline bool QString::isDetached() const
  108.  { return d->ref == 1; }
  109.  inline QString &QString::operator=(const QLatin1String &s)