| 1 | |
| 2 | from rpython.rlib import rutf8 |
| 3 | from rpython.rlib.rstring import StringBuilder, UnicodeBuilder |
| 4 | from rpython.rlib.unicodedata import unicodedb_5_2_0 as unicodedb |
| 5 | |
| 6 | l = ["u" * 100 + str(i) for i in range(100)] |
| 7 | u_l = [unicode("u" * 100 + str(i)) for i in range(100)] |
| 8 | |
| 9 | def descr_upper(s): |
| 10 | builder = rutf8.Utf8StringBuilder(len(s)) |
| 11 | for ch in rutf8.Utf8StringIterator(s): |
| 12 | ch = unicodedb.toupper(ch) |
| 13 | builder.append_code(ch) |
| 14 | return builder.build() |
| 15 | descr_upper._dont_inline_ = True |
| 16 | |
| 17 | def descr_upper_s(s): |
| 18 | builder = StringBuilder(len(s)) |
| 19 | for i in range(len(s)): |
| 20 | ch = s[i] |
| 21 | builder.append(chr(unicodedb.toupper(ord(ch)))) |
| 22 | return builder.build() |
| 23 | |
| 24 | def descr_upper_u(s): |
| 25 | builder = UnicodeBuilder(len(s)) |
| 26 | for ch in s: |
| 27 | builder.append(unichr(unicodedb.toupper(ord(ch)))) |
| 28 | return builder.build() |
| 29 | |
| 30 | def main(argv): |
| 31 | res_l = ["foo"] |
| 32 | res_l_2 = [u"foo"] |
| 33 | if len(argv) > 2 and argv[2] == "s": |
| 34 | for i in range(int(argv[1])): |
| 35 | res_l[0] = descr_upper_s(l[i % 100]) |
| 36 | elif len(argv) > 2 and argv[2] == "u": |
| 37 | for i in range(int(argv[1])): |
| 38 | res_l_2[0] = descr_upper_u(u_l[i % 100]) |
| 39 | else: |
| 40 | for i in range(int(argv[1])): |
| 41 | res_l[0] = descr_upper(l[i % 100]) |
| 42 | return 0 |
| 43 | |
| 44 | def target(*args): |
| 45 | return main |