07-binary-search.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --- contrib/libs/libidn/lib/stringprep.c (index)
  2. +++ contrib/libs/libidn/lib/stringprep.c (working tree)
  3. @@ -86,18 +86,40 @@ stringprep_find_character_in_table (uint32_t ucs4,
  4. }
  5. static ssize_t
  6. +stringprep_find_character_in_table_fast (uint32_t ucs4,
  7. + const Stringprep_table_element * table, size_t table_size)
  8. +{
  9. + int l = 0;
  10. + int r = table_size - 1;
  11. + int pivot = (l + r) / 2;
  12. +
  13. + while (l <= r) {
  14. + if (ucs4 >= table[pivot].start &&
  15. + ucs4 <= (table[pivot].end ? table[pivot].end : table[pivot].start))
  16. + return pivot;
  17. + else if (ucs4 < table[pivot].start)
  18. + r = pivot - 1;
  19. + else
  20. + l = pivot + 1;
  21. + pivot = (l + r) / 2;
  22. + }
  23. + if (l > r)
  24. + return -1;
  25. +}
  26. +
  27. +static ssize_t
  28. stringprep_find_string_in_table (uint32_t *ucs4,
  29. size_t ucs4len,
  30. size_t *tablepos,
  31. const Stringprep_table_element *table,
  32. - size_t table_size)
  33. + const size_t table_size)
  34. {
  35. size_t j;
  36. ssize_t pos;
  37. for (j = 0; j < ucs4len; j++)
  38. if ((pos =
  39. - stringprep_find_character_in_table (ucs4[j], table,
  40. + stringprep_find_character_in_table_fast (ucs4[j], table,
  41. table_size)) != -1)
  42. {
  43. if (tablepos)
  44. @@ -113,7 +135,7 @@ stringprep_apply_table_to_string (uint32_t *ucs4,
  45. size_t *ucs4len,
  46. size_t maxucs4len,
  47. const Stringprep_table_element *table,
  48. - size_t table_size)
  49. + const size_t table_size)
  50. {
  51. ssize_t pos;
  52. size_t i, maplen;
  53. @@ -302,16 +324,12 @@ stringprep_4i (uint32_t *ucs4, size_t *len, size_t maxucs4len,
  54. if (contains_ral != SIZE_MAX)
  55. {
  56. - if (!(stringprep_find_character_in_table
  57. + if (!(stringprep_find_character_in_table_fast
  58. (ucs4[0], profile[contains_ral].table,
  59. - profile[contains_ral].table_size) != -1
  60. - &&
  61. - stringprep_find_character_in_table (ucs4[ucs4len - 1],
  62. - profile
  63. - [contains_ral].table,
  64. - profile
  65. - [contains_ral].table_size)
  66. - != -1))
  67. + profile[contains_ral].table_size) != -1 &&
  68. + stringprep_find_character_in_table_fast
  69. + (ucs4[ucs4len - 1], profile[contains_ral].table,
  70. + profile[contains_ral].table_size) != -1))
  71. return STRINGPREP_BIDI_LEADTRAIL_NOT_RAL;
  72. }
  73. }