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

Side by Side Diff: compiled/String.h

Issue 29587914: Issue 5142 - Convert Element Hiding to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased on master. Created Dec. 5, 2017, 6:01 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
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void grow(size_type additionalSize) 274 void grow(size_type additionalSize)
275 { 275 {
276 OwnedString newValue(length() + additionalSize); 276 OwnedString newValue(length() + additionalSize);
277 if (length() > 0) 277 if (length() > 0)
278 std::memcpy(newValue.mBuf, mBuf, sizeof(value_type) * length()); 278 std::memcpy(newValue.mBuf, mBuf, sizeof(value_type) * length());
279 *this = std::move(newValue); 279 *this = std::move(newValue);
280 } 280 }
281 281
282 public: 282 public:
283 explicit OwnedString(size_type len = 0) 283 explicit OwnedString(size_type len = 0)
284 : String(nullptr, len, READ_WRITE) 284 : String(nullptr, len, len ? READ_WRITE : INVALID)
sergei 2018/01/15 15:31:19 If it's not difficult could you please put the cha
hub 2018/01/16 02:57:39 Done https://codereview.adblockplus.org/29669631/
285 { 285 {
286 if (len) 286 if (len)
287 { 287 {
288 mBuf = new value_type[length()]; 288 mBuf = new value_type[length()];
289 annotate_address(mBuf, "String"); 289 annotate_address(mBuf, "String");
290 } 290 }
291 else 291 else
292 mBuf = nullptr; 292 mBuf = nullptr;
293 } 293 }
294 294
(...skipping 22 matching lines...) Expand all
317 str.mBuf = nullptr; 317 str.mBuf = nullptr;
318 str.mLen = READ_WRITE | 0; 318 str.mLen = READ_WRITE | 0;
319 } 319 }
320 320
321 ~OwnedString() 321 ~OwnedString()
322 { 322 {
323 if (mBuf) 323 if (mBuf)
324 delete[] mBuf; 324 delete[] mBuf;
325 } 325 }
326 326
327 void reset(const String& str)
328 {
329 *this = str;
330 }
331
327 OwnedString& operator=(const String& str) 332 OwnedString& operator=(const String& str)
328 { 333 {
329 *this = OwnedString(str); 334 *this = OwnedString(str);
330 return *this; 335 return *this;
331 } 336 }
332 337
333 OwnedString& operator=(const OwnedString& str) 338 OwnedString& operator=(const OwnedString& str)
334 { 339 {
335 *this = OwnedString(str); 340 *this = OwnedString(str);
336 return *this; 341 return *this;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (negative) 403 if (negative)
399 mBuf[pos++] = '-'; 404 mBuf[pos++] = '-';
400 405
401 for (int i = size - 1; i >= 0; i--) 406 for (int i = size - 1; i >= 0; i--)
402 { 407 {
403 mBuf[pos + i] = '0' + (num % 10); 408 mBuf[pos + i] = '0' + (num % 10);
404 num /= 10; 409 num /= 10;
405 } 410 }
406 } 411 }
407 }; 412 };
OLDNEW

Powered by Google App Engine
This is Rietveld