Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/String.h

Issue 29425555: Issue 5201 - [emscripten] Replace EM_ASM calls by a custom JavaScript library (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created April 30, 2017, 6:54 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/FilterNotifier.cpp ('k') | compiled/debug.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #pragma once 18 #pragma once
19 19
20 #include <algorithm> 20 #include <algorithm>
21 #include <cstddef> 21 #include <cstddef>
22 #include <cstring> 22 #include <cstring>
23 #include <type_traits> 23 #include <type_traits>
24 24
25 #include <emscripten.h> 25 #include <emscripten.h>
26 26
27 #include "debug.h" 27 #include "debug.h"
28 28
29 extern "C"
30 {
31 // It seems that calling JS is the easiest solution for lowercasing Unicode
32 // characters.
33 char16_t CharToLower(char16_t charCode);
34 }
35
29 inline void String_assert_readonly(bool readOnly); 36 inline void String_assert_readonly(bool readOnly);
30 37
31 class String 38 class String
32 { 39 {
33 friend class DependentString; 40 friend class DependentString;
34 friend class OwnedString; 41 friend class OwnedString;
35 42
36 public: 43 public:
37 typedef char16_t value_type; 44 typedef char16_t value_type;
38 typedef size_t size_type; 45 typedef size_t size_type;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 for (size_type i = 0; i < len; ++i) 188 for (size_type i = 0; i < len; ++i)
182 { 189 {
183 value_type currChar = mBuf[i]; 190 value_type currChar = mBuf[i];
184 191
185 // This should be more efficient with a lookup table but I couldn't measur e 192 // This should be more efficient with a lookup table but I couldn't measur e
186 // any performance difference. 193 // any performance difference.
187 if (currChar >= u'A' && currChar <= u'Z') 194 if (currChar >= u'A' && currChar <= u'Z')
188 mBuf[i] = currChar + u'a' - u'A'; 195 mBuf[i] = currChar + u'a' - u'A';
189 else if (currChar >= 128) 196 else if (currChar >= 128)
190 { 197 {
191 // It seems that calling JS is the easiest solution for lowercasing 198 mBuf[i] = CharToLower(currChar);
192 // Unicode characters.
193 mBuf[i] = EM_ASM_INT({
194 return String.fromCharCode($0).toLowerCase().charCodeAt(0);
195 }, currChar);
196 } 199 }
197 } 200 }
198 } 201 }
199 }; 202 };
200 203
201 class DependentString : public String 204 class DependentString : public String
202 { 205 {
203 public: 206 public:
204 explicit DependentString() 207 explicit DependentString()
205 : String(nullptr, 0, INVALID) 208 : String(nullptr, 0, INVALID)
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 if (negative) 406 if (negative)
404 mBuf[pos++] = '-'; 407 mBuf[pos++] = '-';
405 408
406 for (int i = size - 1; i >= 0; i--) 409 for (int i = size - 1; i >= 0; i--)
407 { 410 {
408 mBuf[pos + i] = '0' + (num % 10); 411 mBuf[pos + i] = '0' + (num % 10);
409 num /= 10; 412 num /= 10;
410 } 413 }
411 } 414 }
412 }; 415 };
OLDNEW
« no previous file with comments | « compiled/FilterNotifier.cpp ('k') | compiled/debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld