source: code/trunk/vendor/github.com/andybalholm/brotli/memory.go@ 145

Last change on this file since 145 was 145, checked in by Izuru Yakumo, 22 months ago

Updated the Makefile and vendored depedencies

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 1.1 KB
Line 
1package brotli
2
3/* Copyright 2016 Google Inc. All Rights Reserved.
4
5 Distributed under MIT license.
6 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
7*/
8
9/*
10Dynamically grows array capacity to at least the requested size
11T: data type
12A: array
13C: capacity
14R: requested size
15*/
16func brotli_ensure_capacity_uint8_t(a *[]byte, c *uint, r uint) {
17 if *c < r {
18 var new_size uint = *c
19 if new_size == 0 {
20 new_size = r
21 }
22
23 for new_size < r {
24 new_size *= 2
25 }
26
27 if cap(*a) < int(new_size) {
28 var new_array []byte = make([]byte, new_size)
29 if *c != 0 {
30 copy(new_array, (*a)[:*c])
31 }
32
33 *a = new_array
34 } else {
35 *a = (*a)[:new_size]
36 }
37
38 *c = new_size
39 }
40}
41
42func brotli_ensure_capacity_uint32_t(a *[]uint32, c *uint, r uint) {
43 var new_array []uint32
44 if *c < r {
45 var new_size uint = *c
46 if new_size == 0 {
47 new_size = r
48 }
49
50 for new_size < r {
51 new_size *= 2
52 }
53
54 if cap(*a) < int(new_size) {
55 new_array = make([]uint32, new_size)
56 if *c != 0 {
57 copy(new_array, (*a)[:*c])
58 }
59
60 *a = new_array
61 } else {
62 *a = (*a)[:new_size]
63 }
64 *c = new_size
65 }
66}
Note: See TracBrowser for help on using the repository browser.