Advertisement
Guest User

Untitled

a guest
Sep 6th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. diff -C 3 -r Python-3.2.3_orig/Objects/unicodeobject.c Python-3.2.3/Objects/unicodeobject.c
  2. *** Python-3.2.3_orig/Objects/unicodeobject.c   2012-09-06 16:57:35.000000000 +0200
  3. --- Python-3.2.3/Objects/unicodeobject.c    2012-09-06 17:26:10.000000000 +0200
  4. ***************
  5. *** 7264,7269 ****
  6. --- 7264,7298 ----
  7.  
  8.   #else
  9.  
  10. + #include <stdint.h>
  11. + #include <stdbool.h>
  12. + static uint64_t strCmpEq;
  13. + static uint64_t strCmpLt;
  14. + static uint64_t strCmpGt;
  15. + static uint64_t totalChars;
  16. + static uint64_t comparedChars;
  17. +
  18. + bool strEq(PyUnicodeObject *x, const char *y) {
  19. +   int i;
  20. +   if (strlen(y) != x->length) return false;
  21. +   for (i = 0; i < x->length; i++) {
  22. +       if (x->str[i] != y[i]) {
  23. +           return false;
  24. +       }
  25. +   }
  26. +   return true;
  27. + }
  28. +
  29. + void record(int returnVal) {
  30. +   if (returnVal == -1) {
  31. +       strCmpLt++;
  32. +   } else if (returnVal == 0) {
  33. +       strCmpEq++;
  34. +   } else {
  35. +       strCmpGt++;
  36. +   }
  37. + }
  38. +
  39.   static int
  40.   unicode_compare(PyUnicodeObject *str1, PyUnicodeObject *str2)
  41.   {
  42. ***************
  43. *** 7274,7293 ****
  44.  
  45.       len1 = str1->length;
  46.       len2 = str2->length;
  47.  
  48.       while (len1 > 0 && len2 > 0) {
  49.           Py_UNICODE c1, c2;
  50.  
  51.           c1 = *s1++;
  52.           c2 = *s2++;
  53.  
  54. !         if (c1 != c2)
  55. !             return (c1 < c2) ? -1 : 1;
  56.  
  57.           len1--; len2--;
  58.       }
  59. !
  60. !     return (len1 < len2) ? -1 : (len1 != len2);
  61.   }
  62.  
  63.   #endif
  64. --- 7303,7335 ----
  65.  
  66.       len1 = str1->length;
  67.       len2 = str2->length;
  68. +   totalChars += (len1 < len2) ? len1 : len2;
  69. +   if (strEq(str1, "pleasedumpstats")) {
  70. +       fprintf(stderr, "strCmpEq %ld\n", strCmpEq);
  71. +       fprintf(stderr, "strCmpLt %ld\n", strCmpLt);
  72. +       fprintf(stderr, "strCmpGt %ld\n", strCmpGt);
  73. +       fprintf(stderr, "strCmpTc %ld\n", totalChars);
  74. +       fprintf(stderr, "strCmpCc %ld\n", comparedChars);
  75. +   }
  76.  
  77.       while (len1 > 0 && len2 > 0) {
  78. +       comparedChars++;
  79.           Py_UNICODE c1, c2;
  80.  
  81.           c1 = *s1++;
  82.           c2 = *s2++;
  83.  
  84. !         if (c1 != c2) {
  85. !             int returnVal = (c1 < c2) ? -1 : 1;
  86. !           record(returnVal);
  87. !           return returnVal;
  88. !       }
  89.  
  90.           len1--; len2--;
  91.       }
  92. !   int returnVal = (len1 < len2) ? -1 : (len1 != len2);
  93. !   record(returnVal);
  94. !     return returnVal;
  95.   }
  96.  
  97.   #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement