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

Side by Side Diff: core/src/fxcrt/fx_basic_wstring.cpp

Issue 1116163003: Merge to XFA: Make sure string constructors are efficient on literals (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | xfa/src/fxfa/src/app/xfa_textlayout.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 CFX_WideString::~CFX_WideString() 56 CFX_WideString::~CFX_WideString()
57 { 57 {
58 if (m_pData == NULL) { 58 if (m_pData == NULL) {
59 return; 59 return;
60 } 60 }
61 m_pData->m_nRefs --; 61 m_pData->m_nRefs --;
62 if (m_pData->m_nRefs < 1) { 62 if (m_pData->m_nRefs < 1) {
63 FX_Free(m_pData); 63 FX_Free(m_pData);
64 } 64 }
65 } 65 }
66 void CFX_WideString::InitStr(FX_LPCWSTR lpsz, FX_STRSIZE nLen)
67 {
68 if (nLen < 0) {
69 nLen = lpsz ? (FX_STRSIZE)FXSYS_wcslen(lpsz) : 0;
70 }
71 if (nLen) {
72 m_pData = FX_AllocStringW(nLen);
73 if (!m_pData) {
74 return;
75 }
76 FXSYS_memcpy32(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR));
77 } else {
78 m_pData = NULL;
79 }
80 }
81 CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc) 66 CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc)
82 { 67 {
83 if (stringSrc.m_pData == NULL) { 68 if (stringSrc.m_pData == NULL) {
84 m_pData = NULL; 69 m_pData = NULL;
85 return; 70 return;
86 } 71 }
87 if (stringSrc.m_pData->m_nRefs >= 0) { 72 if (stringSrc.m_pData->m_nRefs >= 0) {
88 m_pData = stringSrc.m_pData; 73 m_pData = stringSrc.m_pData;
89 m_pData->m_nRefs ++; 74 m_pData->m_nRefs ++;
90 } else { 75 } else {
91 m_pData = NULL; 76 m_pData = NULL;
92 *this = stringSrc; 77 *this = stringSrc;
93 } 78 }
94 } 79 }
80 CFX_WideString::CFX_WideString(FX_LPCWSTR lpsz, FX_STRSIZE nLen) {
81 if (nLen < 0) {
82 nLen = lpsz ? (FX_STRSIZE)FXSYS_wcslen(lpsz) : 0;
83 }
84 if (nLen) {
85 m_pData = FX_AllocStringW(nLen);
86 if (m_pData) {
87 FXSYS_memcpy32(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR));
88 }
89 } else {
90 m_pData = NULL;
91 }
92 }
95 CFX_WideString::CFX_WideString(FX_WCHAR ch) 93 CFX_WideString::CFX_WideString(FX_WCHAR ch)
96 { 94 {
97 m_pData = FX_AllocStringW(1); 95 m_pData = FX_AllocStringW(1);
98 if (m_pData) { 96 if (m_pData) {
99 m_pData->m_String[0] = ch; 97 m_pData->m_String[0] = ch;
100 } 98 }
101 } 99 }
102 CFX_WideString::CFX_WideString(const CFX_WideStringC& str) 100 CFX_WideString::CFX_WideString(const CFX_WideStringC& str)
103 { 101 {
104 if (str.IsEmpty()) { 102 if (str.IsEmpty()) {
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 return (CFX_CharMap*)&g_DefaultJISMapper; 1105 return (CFX_CharMap*)&g_DefaultJISMapper;
1108 case 936: 1106 case 936:
1109 return (CFX_CharMap*)&g_DefaultGBKMapper; 1107 return (CFX_CharMap*)&g_DefaultGBKMapper;
1110 case 949: 1108 case 949:
1111 return (CFX_CharMap*)&g_DefaultUHCMapper; 1109 return (CFX_CharMap*)&g_DefaultUHCMapper;
1112 case 950: 1110 case 950:
1113 return (CFX_CharMap*)&g_DefaultBig5Mapper; 1111 return (CFX_CharMap*)&g_DefaultBig5Mapper;
1114 } 1112 }
1115 return NULL; 1113 return NULL;
1116 } 1114 }
OLDNEW
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | xfa/src/fxfa/src/app/xfa_textlayout.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698