Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad9c569

Browse files
committed
delta encoding of upper/lower/title makes a glorious return (#12736)
1 parent da05f45 commit ad9c569

3 files changed

Lines changed: 1356 additions & 3452 deletions

File tree

Objects/unicodectype.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
#define EXTENDED_CASE_MASK 0x4000
2828

2929
typedef struct {
30-
const Py_UCS4 upper;
31-
const Py_UCS4 lower;
32-
const Py_UCS4 title;
30+
/*
31+
These are either deltas to the character or offsets in
32+
_PyUnicode_ExtendedCase.
33+
*/
34+
const int upper;
35+
const int lower;
36+
const int title;
3337
const unsigned char decimal;
3438
const unsigned char digit;
3539
const unsigned short flags;
@@ -60,7 +64,7 @@ Py_UCS4 _PyUnicode_ToTitlecase(register Py_UCS4 ch)
6064
{
6165
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
6266

63-
return ctype->title ? ctype->title : ch;
67+
return ch + ctype->title;
6468
}
6569

6670
/* Returns 1 for Unicode characters having the category 'Lt', 0
@@ -186,7 +190,7 @@ Py_UCS4 _PyUnicode_ToUppercase(Py_UCS4 ch)
186190

187191
if (ctype->flags & EXTENDED_CASE_MASK)
188192
return _PyUnicode_ExtendedCase[ctype->upper & 0xFFFF];
189-
return ctype->upper ? ctype->upper : ch;
193+
return ch + ctype->upper;
190194
}
191195

192196
/* Returns the lowercase Unicode characters corresponding to ch or just
@@ -198,7 +202,7 @@ Py_UCS4 _PyUnicode_ToLowercase(Py_UCS4 ch)
198202

199203
if (ctype->flags & EXTENDED_CASE_MASK)
200204
return _PyUnicode_ExtendedCase[ctype->lower & 0xFFFF];
201-
return ctype->lower ? ctype->lower : ch;
205+
return ch + ctype->lower;
202206
}
203207

204208
int _PyUnicode_ToLowerFull(Py_UCS4 ch, Py_UCS4 *res)
@@ -213,7 +217,7 @@ int _PyUnicode_ToLowerFull(Py_UCS4 ch, Py_UCS4 *res)
213217
res[i] = _PyUnicode_ExtendedCase[index + i];
214218
return n;
215219
}
216-
res[0] = ctype->lower ? ctype->lower : ch;
220+
res[0] = ch + ctype->lower;
217221
return 1;
218222
}
219223

@@ -229,7 +233,7 @@ int _PyUnicode_ToTitleFull(Py_UCS4 ch, Py_UCS4 *res)
229233
res[i] = _PyUnicode_ExtendedCase[index + i];
230234
return n;
231235
}
232-
res[0] = ctype->title ? ctype->title : ch;
236+
res[0] = ch + ctype->title;
233237
return 1;
234238
}
235239

@@ -245,7 +249,7 @@ int _PyUnicode_ToUpperFull(Py_UCS4 ch, Py_UCS4 *res)
245249
res[i] = _PyUnicode_ExtendedCase[index + i];
246250
return n;
247251
}
248-
res[0] = ctype->upper ? ctype->upper : ch;
252+
res[0] = ch + ctype->upper;
249253
return 1;
250254
}
251255

0 commit comments

Comments
 (0)