| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <stddef.h> // For offsetof(). | 7 #include <stddef.h> // For offsetof(). |
| 8 | 8 |
| 9 #include "../../include/fxcrt/fx_basic.h" | 9 #include "../../include/fxcrt/fx_basic.h" |
| 10 #include "../../../third_party/base/numerics/safe_math.h" | 10 #include "../../../third_party/base/numerics/safe_math.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Now round to an 8-byte boundary. We'd expect that this is the minimum | 66 // Now round to an 8-byte boundary. We'd expect that this is the minimum |
| 67 // granularity of any of the underlying allocators, so there may be cases | 67 // granularity of any of the underlying allocators, so there may be cases |
| 68 // where we can save a re-alloc when adding a few characters to a string | 68 // where we can save a re-alloc when adding a few characters to a string |
| 69 // by using this otherwise wasted space. | 69 // by using this otherwise wasted space. |
| 70 nSize += 7; | 70 nSize += 7; |
| 71 int totalSize = nSize.ValueOrDie() & ~7; | 71 int totalSize = nSize.ValueOrDie() & ~7; |
| 72 int usableSize = totalSize - overhead; | 72 int usableSize = totalSize - overhead; |
| 73 FXSYS_assert(usableSize >= nLen); | 73 FXSYS_assert(usableSize >= nLen); |
| 74 | 74 |
| 75 void* pData = FX_Alloc(FX_BYTE, totalSize); | 75 void* pData = FX_Alloc(FX_BYTE, totalSize); |
| 76 if (!pData) { | |
| 77 return NULL; | |
| 78 } | |
| 79 return new (pData) StringData(nLen, usableSize); | 76 return new (pData) StringData(nLen, usableSize); |
| 80 } | 77 } |
| 81 CFX_ByteString::~CFX_ByteString() | 78 CFX_ByteString::~CFX_ByteString() |
| 82 { | 79 { |
| 83 if (m_pData) { | 80 if (m_pData) { |
| 84 m_pData->Release(); | 81 m_pData->Release(); |
| 85 } | 82 } |
| 86 } | 83 } |
| 87 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) | 84 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) |
| 88 { | 85 { |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 scale /= 10; | 1124 scale /= 10; |
| 1128 } | 1125 } |
| 1129 return buf_size; | 1126 return buf_size; |
| 1130 } | 1127 } |
| 1131 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) | 1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) |
| 1132 { | 1129 { |
| 1133 FX_CHAR buf[32]; | 1130 FX_CHAR buf[32]; |
| 1134 FX_STRSIZE len = FX_ftoa(d, buf); | 1131 FX_STRSIZE len = FX_ftoa(d, buf); |
| 1135 return CFX_ByteString(buf, len); | 1132 return CFX_ByteString(buf, len); |
| 1136 } | 1133 } |
| OLD | NEW |