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

Side by Side Diff: compiled/String.h

Issue 29384812: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 1 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Removed unnecessary raw buffer Created April 10, 2017, 6:27 p.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 | « no previous file | compiled/StringMap.h » ('j') | compiled/StringMap.h » ('J')
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
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 { 342 {
343 if (!sourceLen) 343 if (!sourceLen)
344 return; 344 return;
345 345
346 assert(source, u"Null buffer passed to OwnedString.append()"_str); 346 assert(source, u"Null buffer passed to OwnedString.append()"_str);
347 size_t oldLength = length(); 347 size_t oldLength = length();
348 grow(sourceLen); 348 grow(sourceLen);
349 std::memcpy(mBuf + oldLength, source, sizeof(value_type) * sourceLen); 349 std::memcpy(mBuf + oldLength, source, sizeof(value_type) * sourceLen);
350 } 350 }
351 351
352 void append(const char* source, size_type sourceLen)
353 {
354 if (!sourceLen)
355 return;
356
357 assert(source, u"Null buffer passed to OwnedString.append()"_str);
sergei 2017/04/12 12:04:31 I think it makes sense to put this assert before t
hub 2017/04/12 12:12:07 Not sure what the intent is but to me it looks rea
sergei 2017/04/12 12:14:40 Ah, sorry, misread it as `if (!source)...`. It's c
358 size_t oldLength = length();
359 grow(sourceLen);
360 for (size_t i = 0; i < sourceLen; i++)
361 mBuf[oldLength + i] = source[i];
362 }
363
352 void append(const String& str) 364 void append(const String& str)
353 { 365 {
354 append(str.mBuf, str.length()); 366 append(str.mBuf, str.length());
355 } 367 }
356 368
357 void append(value_type c) 369 void append(value_type c)
358 { 370 {
359 append(&c, 1); 371 append(&c, 1);
360 } 372 }
361 373
362 template<typename T, 374 template<typename T,
363 typename std::enable_if<std::is_integral<T>::value>::type* = nullptr> 375 typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
364 void append(T num) 376 void append(T num)
365 { 377 {
366 bool negative = false; 378 bool negative = false;
367 if (num < 0) 379 if (num < 0)
368 { 380 {
369 negative = true; 381 negative = true;
370 num = -num; 382 num = -num;
371 } 383 }
372 384
373 size_type size = 0; 385 size_type size = 0;
374 for (int i = num; i; i /= 10) 386 for (T i = num; i; i /= 10)
375 size++; 387 size++;
376 size = (size ? size : 1); 388 size = (size ? size : 1);
377 389
378 size_type pos = length(); 390 size_type pos = length();
379 grow((negative ? 1 : 0) + size); 391 grow((negative ? 1 : 0) + size);
380 392
381 if (negative) 393 if (negative)
382 mBuf[pos++] = '-'; 394 mBuf[pos++] = '-';
383 395
384 for (int i = size - 1; i >= 0; i--) 396 for (int i = size - 1; i >= 0; i--)
385 { 397 {
386 mBuf[pos + i] = '0' + (num % 10); 398 mBuf[pos + i] = '0' + (num % 10);
387 num /= 10; 399 num /= 10;
388 } 400 }
389 } 401 }
390 }; 402 };
OLDNEW
« no previous file with comments | « no previous file | compiled/StringMap.h » ('j') | compiled/StringMap.h » ('J')

Powered by Google App Engine
This is Rietveld