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 } |
76 return new (pData) StringData(nLen, usableSize); | 79 return new (pData) StringData(nLen, usableSize); |
77 } | 80 } |
78 CFX_ByteString::~CFX_ByteString() | 81 CFX_ByteString::~CFX_ByteString() |
79 { | 82 { |
80 if (m_pData) { | 83 if (m_pData) { |
81 m_pData->Release(); | 84 m_pData->Release(); |
82 } | 85 } |
83 } | 86 } |
84 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) | 87 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) |
85 { | 88 { |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 scale /= 10; | 1127 scale /= 10; |
1125 } | 1128 } |
1126 return buf_size; | 1129 return buf_size; |
1127 } | 1130 } |
1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) | 1131 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) |
1129 { | 1132 { |
1130 FX_CHAR buf[32]; | 1133 FX_CHAR buf[32]; |
1131 FX_STRSIZE len = FX_ftoa(d, buf); | 1134 FX_STRSIZE len = FX_ftoa(d, buf); |
1132 return CFX_ByteString(buf, len); | 1135 return CFX_ByteString(buf, len); |
1133 } | 1136 } |
OLD | NEW |