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

Side by Side Diff: src/core/SkVarAlloc.cpp

Issue 1061783002: Rearrange SkRecord with small N in mind (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 32-bit fix Created 5 years, 8 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 | « src/core/SkVarAlloc.h ('k') | tests/PictureTest.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 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
1 #include "SkVarAlloc.h" 8 #include "SkVarAlloc.h"
2 9
3 // We use non-standard malloc diagnostic methods to make sure our allocations ar e sized well. 10 // We use non-standard malloc diagnostic methods to make sure our allocations ar e sized well.
4 #if defined(SK_BUILD_FOR_MAC) 11 #if defined(SK_BUILD_FOR_MAC)
5 #include <malloc/malloc.h> 12 #include <malloc/malloc.h>
6 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN32) 13 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN32)
7 #include <malloc.h> 14 #include <malloc.h>
8 #endif 15 #endif
9 16
10 struct SkVarAlloc::Block { 17 struct SkVarAlloc::Block {
11 Block* prev; 18 Block* prev;
12 char* data() { return (char*)(this + 1); } 19 char* data() { return (char*)(this + 1); }
13 20
14 static Block* Alloc(Block* prev, size_t size, unsigned flags) { 21 static Block* Alloc(Block* prev, size_t size, unsigned flags) {
15 SkASSERT(size >= sizeof(Block)); 22 SkASSERT(size >= sizeof(Block));
16 Block* b = (Block*)sk_malloc_flags(size, flags); 23 Block* b = (Block*)sk_malloc_flags(size, flags);
17 b->prev = prev; 24 b->prev = prev;
18 return b; 25 return b;
19 } 26 }
20 }; 27 };
21 28
22 SkVarAlloc::SkVarAlloc(size_t minLgSize) 29 SkVarAlloc::SkVarAlloc(size_t minLgSize)
23 : fByte(NULL) 30 : fByte(NULL)
24 , fRemaining(0) 31 , fRemaining(0)
25 , fLgSize(minLgSize) 32 , fLgSize(minLgSize)
26 , fBlock(NULL) {} 33 , fBlock(NULL) {}
27 34
35 SkVarAlloc::SkVarAlloc(size_t minLgSize, char* storage, size_t len)
36 : fByte(storage)
37 , fRemaining(len)
38 , fLgSize(minLgSize)
39 , fBlock(NULL) {}
40
28 SkVarAlloc::~SkVarAlloc() { 41 SkVarAlloc::~SkVarAlloc() {
29 Block* b = fBlock; 42 Block* b = fBlock;
30 while (b) { 43 while (b) {
31 Block* prev = b->prev; 44 Block* prev = b->prev;
32 sk_free(b); 45 sk_free(b);
33 b = prev; 46 b = prev;
34 } 47 }
35 } 48 }
36 49
37 void SkVarAlloc::makeSpace(size_t bytes, unsigned flags) { 50 void SkVarAlloc::makeSpace(size_t bytes, unsigned flags) {
(...skipping 27 matching lines...) Expand all
65 #endif 78 #endif
66 } 79 }
67 80
68 size_t SkVarAlloc::approxBytesAllocated() const { 81 size_t SkVarAlloc::approxBytesAllocated() const {
69 size_t sum = 0; 82 size_t sum = 0;
70 for (Block* b = fBlock; b; b = b->prev) { 83 for (Block* b = fBlock; b; b = b->prev) {
71 sum += heap_size(b); 84 sum += heap_size(b);
72 } 85 }
73 return sum; 86 return sum;
74 } 87 }
OLDNEW
« no previous file with comments | « src/core/SkVarAlloc.h ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698