| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
| 3 * Copyright © 2011,2012 Google, Inc. | 3 * Copyright © 2011,2012 Google, Inc. |
| 4 * | 4 * |
| 5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
| 6 * | 6 * |
| 7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
| 8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
| 9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
| 10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 old.finish (); | 532 old.finish (); |
| 533 l.lock (); | 533 l.lock (); |
| 534 } | 534 } |
| 535 items.finish (); | 535 items.finish (); |
| 536 l.unlock (); | 536 l.unlock (); |
| 537 } | 537 } |
| 538 | 538 |
| 539 }; | 539 }; |
| 540 | 540 |
| 541 | 541 |
| 542 | |
| 543 | |
| 544 /* Big-endian handling */ | |
| 545 | |
| 546 static inline uint16_t hb_be_uint16 (const uint16_t v) | |
| 547 { | |
| 548 const uint8_t *V = (const uint8_t *) &v; | |
| 549 return (V[0] << 8) | V[1]; | |
| 550 } | |
| 551 | |
| 552 static inline uint16_t hb_uint16_swap (const uint16_t v) | |
| 553 { | |
| 554 return (v >> 8) | (v << 8); | |
| 555 } | |
| 556 | |
| 557 static inline uint32_t hb_uint32_swap (const uint32_t v) | |
| 558 { | |
| 559 return (hb_uint16_swap (v) << 16) | hb_uint16_swap (v >> 16); | |
| 560 } | |
| 561 | |
| 562 /* Note, of the following macros, uint16_get is the one called many many times. | |
| 563 * If there is any optimizations to be done, it's in that macro. However, I | |
| 564 * already confirmed that on my T400 ThinkPad at least, using bswap_16(), which | |
| 565 * results in a single ror instruction, does NOT speed this up. In fact, it | |
| 566 * resulted in a minor slowdown. At any rate, note that v may not be correctly | |
| 567 * aligned, so I think the current implementation is optimal. | |
| 568 */ | |
| 569 | |
| 570 #define hb_be_uint16_put(v,V) HB_STMT_START { v[0] = (V>>8); v[1] = (V); } HB_
STMT_END | |
| 571 #define hb_be_uint16_get(v) (uint16_t) ((v[0] << 8) + v[1]) | |
| 572 #define hb_be_uint16_eq(a,b) (a[0] == b[0] && a[1] == b[1]) | |
| 573 | |
| 574 #define hb_be_uint32_put(v,V) HB_STMT_START { v[0] = (V>>24); v[1] = (V>>16);
v[2] = (V>>8); v[3] = (V); } HB_STMT_END | |
| 575 #define hb_be_uint32_get(v) (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2]
<< 8) + v[3]) | |
| 576 #define hb_be_uint32_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] &&
a[3] == b[3]) | |
| 577 | |
| 578 #define hb_be_uint24_put(v,V) HB_STMT_START { v[0] = (V>>16); v[1] = (V>>8); v
[2] = (V); } HB_STMT_END | |
| 579 #define hb_be_uint24_get(v) (uint32_t) ((v[0] << 16) + (v[1] << 8) + v[2]) | |
| 580 #define hb_be_uint24_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) | |
| 581 | |
| 582 | |
| 583 /* ASCII tag/character handling */ | 542 /* ASCII tag/character handling */ |
| 584 | 543 |
| 585 static inline bool ISALPHA (unsigned char c) | 544 static inline bool ISALPHA (unsigned char c) |
| 586 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } | 545 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } |
| 587 static inline bool ISALNUM (unsigned char c) | 546 static inline bool ISALNUM (unsigned char c) |
| 588 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '
9'); } | 547 { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '
9'); } |
| 589 static inline bool ISSPACE (unsigned char c) | 548 static inline bool ISSPACE (unsigned char c) |
| 590 { return c == ' ' || c =='\f'|| c =='\n'|| c =='\r'|| c =='\t'|| c =='\v'; } | 549 { return c == ' ' || c =='\f'|| c =='\n'|| c =='\r'|| c =='\t'|| c =='\v'; } |
| 591 static inline unsigned char TOUPPER (unsigned char c) | 550 static inline unsigned char TOUPPER (unsigned char c) |
| 592 { return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; } | 551 { return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 #define DEBUG_MSG_LEVEL(WHAT, OBJ, LEVEL, LEVEL_DIR, ...) _hb_debug_msg<HB
_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, true, (LEVEL), (LEVEL_DIR), __VA_ARGS__) | 708 #define DEBUG_MSG_LEVEL(WHAT, OBJ, LEVEL, LEVEL_DIR, ...) _hb_debug_msg<HB
_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, true, (LEVEL), (LEVEL_DIR), __VA_ARGS__) |
| 750 #define DEBUG_MSG(WHAT, OBJ, ...) _hb_debug_msg<HB
_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, false, 0, 0, __VA_ARGS__) | 709 #define DEBUG_MSG(WHAT, OBJ, ...) _hb_debug_msg<HB
_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, false, 0, 0, __VA_ARGS__) |
| 751 #define DEBUG_MSG_FUNC(WHAT, OBJ, ...) _hb_debug_msg<HB
_DEBUG_##WHAT> (#WHAT, (OBJ), HB_FUNC, false, 0, 0, __VA_ARGS__) | 710 #define DEBUG_MSG_FUNC(WHAT, OBJ, ...) _hb_debug_msg<HB
_DEBUG_##WHAT> (#WHAT, (OBJ), HB_FUNC, false, 0, 0, __VA_ARGS__) |
| 752 | 711 |
| 753 | 712 |
| 754 /* | 713 /* |
| 755 * Printer | 714 * Printer |
| 756 */ | 715 */ |
| 757 | 716 |
| 758 template <typename T> | 717 template <typename T> |
| 759 struct hb_printer_t {}; | 718 struct hb_printer_t { |
| 719 const char *print (const T&) { return "something"; } |
| 720 }; |
| 760 | 721 |
| 761 template <> | 722 template <> |
| 762 struct hb_printer_t<bool> { | 723 struct hb_printer_t<bool> { |
| 763 const char *print (bool v) { return v ? "true" : "false"; } | 724 const char *print (bool v) { return v ? "true" : "false"; } |
| 764 }; | 725 }; |
| 765 | 726 |
| 766 template <> | 727 template <> |
| 767 struct hb_printer_t<hb_void_t> { | 728 struct hb_printer_t<hb_void_t> { |
| 768 const char *print (hb_void_t) { return ""; } | 729 const char *print (hb_void_t) { return ""; } |
| 769 }; | 730 }; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 | 843 |
| 883 | 844 |
| 884 /* Useful for set-operations on small enums. | 845 /* Useful for set-operations on small enums. |
| 885 * For example, for testing "x ∈ {x1, x2, x3}" use: | 846 * For example, for testing "x ∈ {x1, x2, x3}" use: |
| 886 * (FLAG(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) | 847 * (FLAG(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) |
| 887 */ | 848 */ |
| 888 #define FLAG(x) (1<<(x)) | 849 #define FLAG(x) (1<<(x)) |
| 889 #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(
x)) | 850 #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(
x)) |
| 890 | 851 |
| 891 | 852 |
| 892 template <typename T, typename T2> inline void | 853 template <typename T, typename T2> static inline void |
| 893 hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *),
T2 *array2) | 854 hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *),
T2 *array2) |
| 894 { | 855 { |
| 895 if (unlikely (!len)) | 856 if (unlikely (!len)) |
| 896 return; | 857 return; |
| 897 | 858 |
| 898 unsigned int k = len - 1; | 859 unsigned int k = len - 1; |
| 899 do { | 860 do { |
| 900 unsigned int new_k = 0; | 861 unsigned int new_k = 0; |
| 901 | 862 |
| 902 for (unsigned int j = 0; j < k; j++) | 863 for (unsigned int j = 0; j < k; j++) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 915 array2[j] = array2[j + 1]; | 876 array2[j] = array2[j + 1]; |
| 916 array2[j + 1] = t; | 877 array2[j + 1] = t; |
| 917 } | 878 } |
| 918 | 879 |
| 919 new_k = j; | 880 new_k = j; |
| 920 } | 881 } |
| 921 k = new_k; | 882 k = new_k; |
| 922 } while (k); | 883 } while (k); |
| 923 } | 884 } |
| 924 | 885 |
| 925 template <typename T> inline void | 886 template <typename T> static inline void |
| 926 hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) | 887 hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) |
| 927 { | 888 { |
| 928 hb_bubble_sort (array, len, compar, (int *) NULL); | 889 hb_bubble_sort (array, len, compar, (int *) NULL); |
| 929 } | 890 } |
| 930 | 891 |
| 931 static inline hb_bool_t | 892 static inline hb_bool_t |
| 932 hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
ut) | 893 hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o
ut) |
| 933 { | 894 { |
| 934 /* Pain because we don't know whether s is nul-terminated. */ | 895 /* Pain because we don't know whether s is nul-terminated. */ |
| 935 char buf[64]; | 896 char buf[64]; |
| 936 len = MIN (ARRAY_LENGTH (buf) - 1, len); | 897 len = MIN (ARRAY_LENGTH (buf) - 1, len); |
| 937 strncpy (buf, s, len); | 898 strncpy (buf, s, len); |
| 938 buf[len] = '\0'; | 899 buf[len] = '\0'; |
| 939 | 900 |
| 940 char *end; | 901 char *end; |
| 941 errno = 0; | 902 errno = 0; |
| 942 unsigned long v = strtoul (buf, &end, base); | 903 unsigned long v = strtoul (buf, &end, base); |
| 943 if (errno) return false; | 904 if (errno) return false; |
| 944 if (*end) return false; | 905 if (*end) return false; |
| 945 *out = v; | 906 *out = v; |
| 946 return true; | 907 return true; |
| 947 } | 908 } |
| 948 | 909 |
| 949 | 910 |
| 950 /* Global runtime options. */ | 911 /* Global runtime options. */ |
| 951 | 912 |
| 952 struct hb_options_t | 913 struct hb_options_t |
| 953 { | 914 { |
| 954 int initialized : 1; | 915 unsigned int initialized : 1; |
| 955 int uniscribe_bug_compatible : 1; | 916 unsigned int uniscribe_bug_compatible : 1; |
| 956 }; | 917 }; |
| 957 | 918 |
| 958 union hb_options_union_t { | 919 union hb_options_union_t { |
| 959 int i; | 920 unsigned int i; |
| 960 hb_options_t opts; | 921 hb_options_t opts; |
| 961 }; | 922 }; |
| 962 ASSERT_STATIC (sizeof (int) == sizeof (hb_options_union_t)); | 923 ASSERT_STATIC (sizeof (int) == sizeof (hb_options_union_t)); |
| 963 | 924 |
| 964 HB_INTERNAL void | 925 HB_INTERNAL void |
| 965 _hb_options_init (void); | 926 _hb_options_init (void); |
| 966 | 927 |
| 967 extern HB_INTERNAL hb_options_union_t _hb_options; | 928 extern HB_INTERNAL hb_options_union_t _hb_options; |
| 968 | 929 |
| 969 static inline hb_options_t | 930 static inline hb_options_t |
| 970 hb_options (void) | 931 hb_options (void) |
| 971 { | 932 { |
| 972 if (unlikely (!_hb_options.i)) | 933 if (unlikely (!_hb_options.i)) |
| 973 _hb_options_init (); | 934 _hb_options_init (); |
| 974 | 935 |
| 975 return _hb_options.opts; | 936 return _hb_options.opts; |
| 976 } | 937 } |
| 977 | 938 |
| 978 | 939 |
| 979 #endif /* HB_PRIVATE_HH */ | 940 #endif /* HB_PRIVATE_HH */ |
| OLD | NEW |