| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ | 7 #ifndef CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ |
| 8 #define CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ | 8 #define CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ |
| 9 | 9 |
| 10 #include "core/fxcrt/fx_memory.h" | 10 #include "core/fxcrt/fx_memory.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 offsetof(CFX_StringDataTemplate, m_String) + sizeof(CharType); | 23 offsetof(CFX_StringDataTemplate, m_String) + sizeof(CharType); |
| 24 pdfium::base::CheckedNumeric<int> nSize = nLen; | 24 pdfium::base::CheckedNumeric<int> nSize = nLen; |
| 25 nSize *= sizeof(CharType); | 25 nSize *= sizeof(CharType); |
| 26 nSize += overhead; | 26 nSize += overhead; |
| 27 | 27 |
| 28 // Now round to an 8-byte boundary. We'd expect that this is the minimum | 28 // Now round to an 8-byte boundary. We'd expect that this is the minimum |
| 29 // granularity of any of the underlying allocators, so there may be cases | 29 // granularity of any of the underlying allocators, so there may be cases |
| 30 // where we can save a re-alloc when adding a few characters to a string | 30 // where we can save a re-alloc when adding a few characters to a string |
| 31 // by using this otherwise wasted space. | 31 // by using this otherwise wasted space. |
| 32 nSize += 7; | 32 nSize += 7; |
| 33 int totalSize = nSize.ValueOrDie() & ~7; | 33 nSize &= ~7; |
| 34 int totalSize = nSize.ValueOrDie(); |
| 34 int usableLen = (totalSize - overhead) / sizeof(CharType); | 35 int usableLen = (totalSize - overhead) / sizeof(CharType); |
| 35 ASSERT(usableLen >= nLen); | 36 ASSERT(usableLen >= nLen); |
| 36 | 37 |
| 37 void* pData = FX_Alloc(uint8_t, totalSize); | 38 void* pData = FX_Alloc(uint8_t, totalSize); |
| 38 return new (pData) CFX_StringDataTemplate(nLen, usableLen); | 39 return new (pData) CFX_StringDataTemplate(nLen, usableLen); |
| 39 } | 40 } |
| 40 | 41 |
| 41 static CFX_StringDataTemplate* Create(const CFX_StringDataTemplate& other) { | 42 static CFX_StringDataTemplate* Create(const CFX_StringDataTemplate& other) { |
| 42 CFX_StringDataTemplate* result = Create(other.m_nDataLength); | 43 CFX_StringDataTemplate* result = Create(other.m_nDataLength); |
| 43 result->CopyContents(other); | 44 result->CopyContents(other); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 m_String[dataLen] = 0; | 107 m_String[dataLen] = 0; |
| 107 } | 108 } |
| 108 | 109 |
| 109 ~CFX_StringDataTemplate() = delete; | 110 ~CFX_StringDataTemplate() = delete; |
| 110 }; | 111 }; |
| 111 | 112 |
| 112 extern template class CFX_StringDataTemplate<FX_CHAR>; | 113 extern template class CFX_StringDataTemplate<FX_CHAR>; |
| 113 extern template class CFX_StringDataTemplate<FX_WCHAR>; | 114 extern template class CFX_StringDataTemplate<FX_WCHAR>; |
| 114 | 115 |
| 115 #endif // CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ | 116 #endif // CORE_FXCRT_CFX_STRING_DATA_TEMPLATE_H_ |
| OLD | NEW |