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

Side by Side Diff: core/include/fxcrt/fx_basic.h

Issue 1719543002: Tidy CFX_FixedBufGrow. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: explicit. Created 4 years, 10 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 | « no previous file | no next file » | 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 #ifndef CORE_INCLUDE_FXCRT_FX_BASIC_H_ 7 #ifndef CORE_INCLUDE_FXCRT_FX_BASIC_H_
8 #define CORE_INCLUDE_FXCRT_FX_BASIC_H_ 8 #define CORE_INCLUDE_FXCRT_FX_BASIC_H_
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 569
570 void Add(ElementType data) { 570 void Add(ElementType data) {
571 *(ElementType*)CFX_BaseSegmentedArray::Add() = data; 571 *(ElementType*)CFX_BaseSegmentedArray::Add() = data;
572 } 572 }
573 573
574 ElementType& operator[](int index) { 574 ElementType& operator[](int index) {
575 return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index); 575 return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index);
576 } 576 }
577 }; 577 };
578 #endif // PDF_ENABLE_XFA 578 #endif // PDF_ENABLE_XFA
579
579 template <class DataType, int FixedSize> 580 template <class DataType, int FixedSize>
580 class CFX_FixedBufGrow { 581 class CFX_FixedBufGrow {
581 public: 582 public:
582 CFX_FixedBufGrow() : m_pData(NULL) {} 583 explicit CFX_FixedBufGrow(int data_size) {
583 CFX_FixedBufGrow(int data_size) : m_pData(NULL) {
584 if (data_size > FixedSize) { 584 if (data_size > FixedSize) {
585 m_pData = FX_Alloc(DataType, data_size); 585 m_pGrowData.reset(FX_Alloc(DataType, data_size));
586 } else { 586 return;
587 FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize);
588 } 587 }
588 FXSYS_memset(m_FixedData, 0, sizeof(DataType) * FixedSize);
589 } 589 }
590 void SetDataSize(int data_size) { 590 operator DataType*() { return m_pGrowData ? m_pGrowData.get() : m_FixedData; }
591 FX_Free(m_pData);
592 m_pData = NULL;
593 if (data_size > FixedSize) {
594 m_pData = FX_Alloc(DataType, data_size);
595 } else {
596 FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize);
597 }
598 }
599 ~CFX_FixedBufGrow() { FX_Free(m_pData); }
600 operator DataType*() { return m_pData ? m_pData : m_Data; }
601 591
602 private: 592 private:
603 DataType m_Data[FixedSize]; 593 DataType m_FixedData[FixedSize];
604 DataType* m_pData; 594 std::unique_ptr<DataType, FxFreeDeleter> m_pGrowData;
605 }; 595 };
596
606 #ifdef PDF_ENABLE_XFA 597 #ifdef PDF_ENABLE_XFA
607 class CFX_MapPtrToPtr { 598 class CFX_MapPtrToPtr {
608 protected: 599 protected:
609 struct CAssoc { 600 struct CAssoc {
610 CAssoc* pNext; 601 CAssoc* pNext;
611 602
612 void* key; 603 void* key;
613 604
614 void* value; 605 void* value;
615 }; 606 };
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 FX_FLOAT c; 1162 FX_FLOAT c;
1172 FX_FLOAT d; 1163 FX_FLOAT d;
1173 FX_FLOAT e; 1164 FX_FLOAT e;
1174 FX_FLOAT f; 1165 FX_FLOAT f;
1175 FX_FLOAT g; 1166 FX_FLOAT g;
1176 FX_FLOAT h; 1167 FX_FLOAT h;
1177 FX_FLOAT i; 1168 FX_FLOAT i;
1178 }; 1169 };
1179 1170
1180 #endif // CORE_INCLUDE_FXCRT_FX_BASIC_H_ 1171 #endif // CORE_INCLUDE_FXCRT_FX_BASIC_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698