1 From bf05e232805f6c1fae5dea3c223de8bdaab425e9 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
3 Date: Mon, 23 Jan 2017 13:26:53 +0000
4 Subject: [PATCH 1/3] unroll this a bit
7 src/hunspell/csutil.cxx | 49 ++++++++++++++++++++++++++++---------------------
8 1 file changed, 28 insertions(+), 21 deletions(-)
10 diff --git a/src/hunspell/csutil.cxx b/src/hunspell/csutil.cxx
11 index ac5cd98..c1666a5 100644
12 --- a/src/hunspell/csutil.cxx
13 +++ b/src/hunspell/csutil.cxx
14 @@ -518,18 +518,20 @@ unsigned char ccase(const struct cs_info* csconv, int nIndex) {
16 w_char upper_utf(w_char u, int langnum) {
17 unsigned short idx = (u.h << 8) + u.l;
18 - if (idx != unicodetoupper(idx, langnum)) {
19 - u.h = (unsigned char)(unicodetoupper(idx, langnum) >> 8);
20 - u.l = (unsigned char)(unicodetoupper(idx, langnum) & 0x00FF);
21 + unsigned short upridx = unicodetoupper(idx, langnum);
22 + if (idx != upridx) {
23 + u.h = (unsigned char)(upridx >> 8);
24 + u.l = (unsigned char)(upridx & 0x00FF);
29 w_char lower_utf(w_char u, int langnum) {
30 unsigned short idx = (u.h << 8) + u.l;
31 - if (idx != unicodetolower(idx, langnum)) {
32 - u.h = (unsigned char)(unicodetolower(idx, langnum) >> 8);
33 - u.l = (unsigned char)(unicodetolower(idx, langnum) & 0x00FF);
34 + unsigned short lwridx = unicodetolower(idx, langnum);
35 + if (idx != lwridx) {
36 + u.h = (unsigned char)(lwridx >> 8);
37 + u.l = (unsigned char)(lwridx & 0x00FF);
41 @@ -551,12 +553,13 @@ std::string& mkallsmall(std::string& s, const struct cs_info* csconv) {
44 std::vector<w_char>& mkallsmall_utf(std::vector<w_char>& u,
47 for (size_t i = 0; i < u.size(); ++i) {
48 unsigned short idx = (u[i].h << 8) + u[i].l;
49 - if (idx != unicodetolower(idx, langnum)) {
50 - u[i].h = (unsigned char)(unicodetolower(idx, langnum) >> 8);
51 - u[i].l = (unsigned char)(unicodetolower(idx, langnum) & 0x00FF);
52 + unsigned short lwridx = unicodetolower(idx, langnum);
53 + if (idx != lwridx) {
54 + u[i].h = (unsigned char)(lwridx >> 8);
55 + u[i].l = (unsigned char)(lwridx & 0x00FF);
59 @@ -565,9 +568,10 @@ std::vector<w_char>& mkallsmall_utf(std::vector<w_char>& u,
60 std::vector<w_char>& mkallcap_utf(std::vector<w_char>& u, int langnum) {
61 for (size_t i = 0; i < u.size(); i++) {
62 unsigned short idx = (u[i].h << 8) + u[i].l;
63 - if (idx != unicodetoupper(idx, langnum)) {
64 - u[i].h = (unsigned char)(unicodetoupper(idx, langnum) >> 8);
65 - u[i].l = (unsigned char)(unicodetoupper(idx, langnum) & 0x00FF);
66 + unsigned short upridx = unicodetoupper(idx, langnum);
67 + if (idx != upridx) {
68 + u[i].h = (unsigned char)(upridx >> 8);
69 + u[i].l = (unsigned char)(upridx & 0x00FF);
73 @@ -583,9 +587,10 @@ std::string& mkinitcap(std::string& s, const struct cs_info* csconv) {
74 std::vector<w_char>& mkinitcap_utf(std::vector<w_char>& u, int langnum) {
76 unsigned short idx = (u[0].h << 8) + u[0].l;
77 - if (idx != unicodetoupper(idx, langnum)) {
78 - u[0].h = (unsigned char)(unicodetoupper(idx, langnum) >> 8);
79 - u[0].l = (unsigned char)(unicodetoupper(idx, langnum) & 0x00FF);
80 + unsigned short upridx = unicodetoupper(idx, langnum);
81 + if (idx != upridx) {
82 + u[0].h = (unsigned char)(upridx >> 8);
83 + u[0].l = (unsigned char)(upridx & 0x00FF);
87 @@ -601,9 +606,10 @@ std::string& mkinitsmall(std::string& s, const struct cs_info* csconv) {
88 std::vector<w_char>& mkinitsmall_utf(std::vector<w_char>& u, int langnum) {
90 unsigned short idx = (u[0].h << 8) + u[0].l;
91 - if (idx != unicodetolower(idx, langnum)) {
92 - u[0].h = (unsigned char)(unicodetolower(idx, langnum) >> 8);
93 - u[0].l = (unsigned char)(unicodetolower(idx, langnum) & 0x00FF);
94 + unsigned short lwridx = unicodetolower(idx, langnum);
95 + if (idx != lwridx) {
96 + u[0].h = (unsigned char)(lwridx >> 8);
97 + u[0].l = (unsigned char)(lwridx & 0x00FF);
101 @@ -2533,9 +2539,10 @@ int get_captype_utf8(const std::vector<w_char>& word, int langnum) {
103 for (size_t i = 0; i < word.size(); ++i) {
104 unsigned short idx = (word[i].h << 8) + word[i].l;
105 - if (idx != unicodetolower(idx, langnum))
106 + unsigned short lwridx = unicodetolower(idx, langnum);
109 - if (unicodetoupper(idx, langnum) == unicodetolower(idx, langnum))
110 + if (unicodetoupper(idx, langnum) == lwridx)