OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkReader32.h" | 8 #include "SkReader32.h" |
9 #include "SkString.h" | 9 #include "SkString.h" |
10 #include "SkWriter32.h" | 10 #include "SkWriter32.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 size_t SkWriter32::WriteStringSize(const char* str, size_t len) { | 56 size_t SkWriter32::WriteStringSize(const char* str, size_t len) { |
57 if ((long)len < 0) { | 57 if ((long)len < 0) { |
58 SkASSERT(str); | 58 SkASSERT(str); |
59 len = strlen(str); | 59 len = strlen(str); |
60 } | 60 } |
61 const size_t lenBytes = 4; // we use 4 bytes to record the length | 61 const size_t lenBytes = 4; // we use 4 bytes to record the length |
62 // add 1 since we also write a terminating 0 | 62 // add 1 since we also write a terminating 0 |
63 return SkAlign4(lenBytes + len + 1); | 63 return SkAlign4(lenBytes + len + 1); |
64 } | 64 } |
65 | 65 |
66 const size_t kMinBufferBytes = 4096; | |
67 | |
68 void SkWriter32::growToAtLeast(size_t size) { | 66 void SkWriter32::growToAtLeast(size_t size) { |
69 const bool wasExternal = (fExternal != NULL) && (fData == fExternal); | 67 const bool wasExternal = (fExternal != NULL) && (fData == fExternal); |
70 const size_t minCapacity = kMinBufferBytes + | |
71 SkTMax(size, fCapacity + (fCapacity >> 1)); | |
72 | 68 |
73 // cause the buffer to grow | 69 fCapacity = 4096 + SkTMax(size, fCapacity + (fCapacity / 2)); |
74 fInternal.setCountExact(minCapacity); | 70 fInternal.realloc(fCapacity); |
75 fData = fInternal.begin(); | 71 fData = fInternal.get(); |
76 fCapacity = fInternal.reserved(); | 72 |
77 if (wasExternal) { | 73 if (wasExternal) { |
78 // we were external, so copy in the data | 74 // we were external, so copy in the data |
79 memcpy(fData, fExternal, fUsed); | 75 memcpy(fData, fExternal, fUsed); |
80 } | 76 } |
81 } | 77 } |
OLD | NEW |