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

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

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: self review Created 5 years 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
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 "core/include/fxcrt/fx_basic.h" 7 #include "core/include/fxcrt/fx_basic.h"
8 #include "plex.h" 8 #include "plex.h"
9 9
10 CFX_PtrList::CFX_PtrList(int nBlockSize) 10 CFX_PtrList::CFX_PtrList(int nBlockSize)
(...skipping 19 matching lines...) Expand all
30 pNewNode->data = newElement; 30 pNewNode->data = newElement;
31 if (m_pNodeHead) { 31 if (m_pNodeHead) {
32 m_pNodeHead->pPrev = pNewNode; 32 m_pNodeHead->pPrev = pNewNode;
33 } else { 33 } else {
34 m_pNodeTail = pNewNode; 34 m_pNodeTail = pNewNode;
35 } 35 }
36 m_pNodeHead = pNewNode; 36 m_pNodeHead = pNewNode;
37 return (FX_POSITION)pNewNode; 37 return (FX_POSITION)pNewNode;
38 } 38 }
39 FX_POSITION CFX_PtrList::InsertAfter(FX_POSITION position, void* newElement) { 39 FX_POSITION CFX_PtrList::InsertAfter(FX_POSITION position, void* newElement) {
40 if (position == NULL) { 40 if (!position) {
41 return AddTail(newElement); 41 return AddTail(newElement);
42 } 42 }
43 CNode* pOldNode = (CNode*)position; 43 CNode* pOldNode = (CNode*)position;
44 CNode* pNewNode = NewNode(pOldNode, pOldNode->pNext); 44 CNode* pNewNode = NewNode(pOldNode, pOldNode->pNext);
45 pNewNode->data = newElement; 45 pNewNode->data = newElement;
46 if (pOldNode->pNext) { 46 if (pOldNode->pNext) {
47 pOldNode->pNext->pPrev = pNewNode; 47 pOldNode->pNext->pPrev = pNewNode;
48 } else { 48 } else {
49 m_pNodeTail = pNewNode; 49 m_pNodeTail = pNewNode;
50 } 50 }
(...skipping 23 matching lines...) Expand all
74 } 74 }
75 } 75 }
76 void CFX_PtrList::RemoveAll() { 76 void CFX_PtrList::RemoveAll() {
77 m_nCount = 0; 77 m_nCount = 0;
78 m_pNodeHead = m_pNodeTail = m_pNodeFree = NULL; 78 m_pNodeHead = m_pNodeTail = m_pNodeFree = NULL;
79 m_pBlocks->FreeDataChain(); 79 m_pBlocks->FreeDataChain();
80 m_pBlocks = NULL; 80 m_pBlocks = NULL;
81 } 81 }
82 CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev, 82 CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev,
83 CFX_PtrList::CNode* pNext) { 83 CFX_PtrList::CNode* pNext) {
84 if (m_pNodeFree == NULL) { 84 if (!m_pNodeFree) {
85 CFX_Plex* pNewBlock = 85 CFX_Plex* pNewBlock =
86 CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode)); 86 CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode));
87 CNode* pNode = (CNode*)pNewBlock->data(); 87 CNode* pNode = (CNode*)pNewBlock->data();
88 pNode += m_nBlockSize - 1; 88 pNode += m_nBlockSize - 1;
89 for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) { 89 for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) {
90 pNode->pNext = m_pNodeFree; 90 pNode->pNext = m_pNodeFree;
91 m_pNodeFree = pNode; 91 m_pNodeFree = pNode;
92 } 92 }
93 } 93 }
94 ASSERT(m_pNodeFree); 94 ASSERT(m_pNodeFree);
(...skipping 14 matching lines...) Expand all
109 if (nIndex >= m_nCount || nIndex < 0) { 109 if (nIndex >= m_nCount || nIndex < 0) {
110 return NULL; 110 return NULL;
111 } 111 }
112 CNode* pNode = m_pNodeHead; 112 CNode* pNode = m_pNodeHead;
113 while (nIndex--) { 113 while (nIndex--) {
114 pNode = pNode->pNext; 114 pNode = pNode->pNext;
115 } 115 }
116 return (FX_POSITION)pNode; 116 return (FX_POSITION)pNode;
117 } 117 }
118 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const { 118 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const {
119 CNode* pNode = (CNode*)startAfter; 119 CNode* pNode = (CNode*)startAfter;
Tom Sepez 2015/12/14 18:27:00 nit: This calls for a ? operator here.
Lei Zhang 2015/12/15 01:58:36 Done.
120 if (pNode == NULL) { 120 if (pNode) {
121 pNode = pNode->pNext;
122 } else {
121 pNode = m_pNodeHead; 123 pNode = m_pNodeHead;
122 } else {
123 pNode = pNode->pNext;
124 } 124 }
125 for (; pNode; pNode = pNode->pNext) { 125 for (; pNode; pNode = pNode->pNext) {
126 if (pNode->data == searchValue) { 126 if (pNode->data == searchValue) {
127 return (FX_POSITION)pNode; 127 return (FX_POSITION)pNode;
128 } 128 }
129 } 129 }
130 return NULL; 130 return NULL;
131 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698