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

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

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