Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2144)

Unified Diff: core/fxcrt/include/fx_string.h

Issue 1844073003: Make StringData a templated class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« core/fxcrt/fx_basic_bstring.cpp ('K') | « core/fxcrt/fx_basic_bstring.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/include/fx_string.h
diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h
index f73a1345b9e97537ffa035b5272dc7b964a1e3b9..ea7efc94e8f522cf8ef8a35202104371539eabce 100644
--- a/core/fxcrt/include/fx_string.h
+++ b/core/fxcrt/include/fx_string.h
@@ -10,10 +10,14 @@
#include <stdint.h> // For intptr_t.
#include <algorithm>
+#include "core/fxcrt/cfx_string_data_template.h"
#include "core/fxcrt/include/cfx_retain_ptr.h"
#include "core/fxcrt/include/fx_memory.h"
#include "core/fxcrt/include/fx_system.h"
+extern template class CFX_StringDataTemplate<FX_CHAR>;
+extern template class CFX_StringDataTemplate<FX_WCHAR>;
+
class CFX_BinaryBuf;
class CFX_ByteString;
class CFX_WideString;
@@ -279,49 +283,7 @@ class CFX_ByteString {
static CFX_ByteString FormatFloat(FX_FLOAT f, int precision = 0);
protected:
- class StringData {
- public:
- static StringData* Create(FX_STRSIZE nLen);
- static StringData* Create(const StringData& other);
- static StringData* Create(const FX_CHAR* pStr, FX_STRSIZE nLen);
-
- void Retain() { ++m_nRefs; }
- void Release() {
- if (--m_nRefs <= 0)
- FX_Free(this);
- }
-
- bool CanOperateInPlace(FX_STRSIZE nTotalLen) const {
- return m_nRefs <= 1 && nTotalLen <= m_nAllocLength;
- }
-
- void CopyContents(const StringData& other);
- void CopyContents(const FX_CHAR* pStr, FX_STRSIZE nLen);
- void CopyContentsAt(FX_STRSIZE offset,
- const FX_CHAR* pStr,
- FX_STRSIZE nLen);
-
- // To ensure ref counts do not overflow, consider the worst possible case:
- // the entire address space contains nothing but pointers to this object.
- // Since the count increments with each new pointer, the largest value is
- // the number of pointers that can fit into the address space. The size of
- // the address space itself is a good upper bound on it.
- intptr_t m_nRefs; // Would prefer ssize_t, but no windows support.
-
- // |FX_STRSIZE| is currently typedef'd as |int|.
- // TODO(palmer): It should be a |size_t|, or at least unsigned.
- // These lengths do not include the terminating NUL, but the underlying
- // buffer is sized to be capable of holding it.
- FX_STRSIZE m_nDataLength;
- FX_STRSIZE m_nAllocLength;
-
- // Not really 1, variable size.
- FX_CHAR m_String[1];
-
- private:
- StringData(FX_STRSIZE dataLen, FX_STRSIZE allocLen);
- ~StringData() = delete;
- };
+ using StringData = CFX_StringDataTemplate<FX_CHAR>;
void CopyBeforeWrite();
void AllocBeforeWrite(FX_STRSIZE nLen);
« core/fxcrt/fx_basic_bstring.cpp ('K') | « core/fxcrt/fx_basic_bstring.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698