├── go.sum ├── go.mod ├── .github └── workflows │ └── check.yaml ├── pool.go ├── README.md ├── pool_test.go └── LICENSE /go.sum: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/colega/zeropool 2 | 3 | go 1.20 4 | -------------------------------------------------------------------------------- /.github/workflows/check.yaml: -------------------------------------------------------------------------------- 1 | name: Check 2 | on: 3 | - push 4 | jobs: 5 | check: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v3 9 | - name: Set up Go 10 | uses: actions/setup-go@v4 11 | with: 12 | go-version: '^1.20.2' 13 | - name: Test 14 | run: go test -v -race ./... 15 | - name: Lint 16 | uses: golangci/golangci-lint-action@v3 17 | with: 18 | version: v1.51 -------------------------------------------------------------------------------- /pool.go: -------------------------------------------------------------------------------- 1 | package zeropool 2 | 3 | import "sync" 4 | 5 | // Pool is a type-safe pool of items that does not allocate pointers to items. 6 | // That is not entirely true, it does allocate sometimes, but not most of the time, 7 | // just like the usual sync.Pool pools items most of the time, except when they're evicted. 8 | // It does that by storing the allocated pointers in a secondary pool instead of letting them go, 9 | // so they can be used later to store the items again. 10 | // 11 | // Zero value of Pool[T] is valid, and it will return zero values of T if nothing is pooled. 12 | type Pool[T any] struct { 13 | // items holds pointers to the pooled items, which are valid to be used. 14 | items sync.Pool 15 | // pointers holds just pointers to the pooled item types. 16 | // The values referenced by pointers are not valid to be used (as they're used by some other caller) 17 | // and it is safe to overwrite these pointers. 18 | pointers sync.Pool 19 | } 20 | 21 | // New creates a new Pool[T] with the given function to create new items. 22 | // A Pool must not be copied after first use. 23 | func New[T any](item func() T) Pool[T] { 24 | return Pool[T]{ 25 | items: sync.Pool{ 26 | New: func() interface{} { 27 | val := item() 28 | return &val 29 | }, 30 | }, 31 | } 32 | } 33 | 34 | // Get returns an item from the pool, creating a new one if necessary. 35 | // Get may be called concurrently from multiple goroutines. 36 | func (p *Pool[T]) Get() T { 37 | pooled := p.items.Get() 38 | if pooled == nil { 39 | // The only way this can happen is when someone is using the zero-value of zeropool.Pool, and items pool is empty. 40 | // We don't have a pointer to store in p.pointers, so just return the empty value. 41 | var zero T 42 | return zero 43 | } 44 | 45 | ptr := pooled.(*T) 46 | item := *ptr 47 | var zero T 48 | // We don't want to retain the value in p.pointers. 49 | // If T holds a reference to something, we want that to be garbage-collected 50 | // if for some reason caller does less Put() calls than Get() calls. 51 | *ptr = zero 52 | p.pointers.Put(ptr) 53 | return item 54 | } 55 | 56 | // Put adds an item to the pool. 57 | func (p *Pool[T]) Put(item T) { 58 | var ptr *T 59 | if pooled := p.pointers.Get(); pooled != nil { 60 | ptr = pooled.(*T) 61 | } else { 62 | ptr = new(T) 63 | } 64 | *ptr = item 65 | p.items.Put(ptr) 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `zeropool` is a zero-allocation type-safe `sync.Pool` 2 | 3 | ## TL;DR 4 | 5 | ```go 6 | // Zero-value of zeropool.Pool is valid, although the constructor zeropool.New(item func() T) can be used if we want zero values to be initialized. 7 | var pool zeropool.Pool[[]byte] 8 | 9 | // This is a []byte, no need to make type-assertion, no need to de-reference. 10 | buf := pool.Get() 11 | 12 | // This does not allocate. 13 | pool.Put(buf) 14 | ``` 15 | 16 | ## Why? 17 | 18 | [Go provides](https://pkg.go.dev/sync#Pool) `sync.Pool` pool implementation that allows storing `any` values (`interface{}` values). It is great but has two major drawbacks: 19 | - It's not type-safe, a type-assertion is needed on the elements provided by `Get()`. 20 | - Since it stores `interface{}` values, it means that your value will escape[^1] to the heap unless you store a pointer (it would escape, but maybe just once). 21 | 22 | The second drawback is a major one, and actually is the reason why [Staticcheck SA6002](https://staticcheck.io/docs/checks#SA6002) exists. It's not unusual, for example, to use `sync.Pool` to store allocated byte slices, in which case one would do: 23 | 24 | ```go 25 | var pool = sync.Pool{New: func() any { return new([]byte) }} 26 | 27 | func do() { 28 | buf := pool.Get().(*[]byte) 29 | 30 | *buf = somethingThatNeedsABuffer(*buf) 31 | pool.Put(buf[:0]) 32 | } 33 | 34 | func somethingThatNeedsABuffer(buf []byte) buf { 35 | buf = append(buf, []byte("something uselesss")...) 36 | return buf 37 | } 38 | ``` 39 | 40 | Not great (we have to do a type assertion), not terrible (the scope is small). 41 | 42 | However, sometimes[^2][^3][^4] we would want to pass that buffer to a function that would only accept `[]byte`, and that has its own lifecycle so it would take the responsibility of putting it back to the pool: 43 | 44 | ```go 45 | var pool = sync.Pool{New: func() any { return new([]byte) }} 46 | 47 | func do() { 48 | buf := pool.Get().(*[]byte) 49 | go somethingThatNeedsABuffer(*buf) 50 | } 51 | 52 | func somethingThatNeedsABuffer(buf []byte) { 53 | buf = append(buf, []byte("something uselesss")...) 54 | pool.Put(&buf) 55 | } 56 | ``` 57 | 58 | Note that in this case, our function `somethingThatNeedsABuffer` allocates a new pointer to that slice. 59 | 60 | Enter `zeropool`: 61 | 62 | ```go 63 | var pool = zeropool.New(func() []byte { return nil }) 64 | 65 | func do() { 66 | buf := pool.Get() 67 | go somethingThatNeedsABuffer(buf) 68 | } 69 | 70 | func somethingThatNeedsABuffer(buf []byte) { 71 | buf = append(buf, []byte("something uselesss")...) 72 | pool.Put(buf) 73 | } 74 | ``` 75 | 76 | ## How to solve "SA6002 - Storing non-pointer values in sync.Pool allocates memory" 77 | 78 | Replace your `sync.Pool` implementation by `zeropool.Pool`, and you also get the type-safety for free. 79 | 80 | ## How does it work? 81 | 82 | `zeropool` maintains two `sync.Pool` instances: one is used as the main pool for pointers to the stored items. 83 | The second pool is used to hold the pointers while the code is using the items from the pool. 84 | 85 | ## Performance 86 | 87 | It is approximately ~2x slower than `sync.Pool` if what you are storing are pointers: it doesn't make sense to pay the price in that case. 88 | However, if you have no option but to store elements, and you need to allocate new pointers to store into `sync.Pool`, `zeropool` becomes 2-3x faster. 89 | 90 | ``` 91 | go test -run=X -bench=. -count=10 -benchmem | tee /tmp/zeropool.bench && benchstat -col .name /tmp/zeropool.bench 92 | goos: darwin 93 | goarch: amd64 94 | pkg: github.com/colega/zeropool 95 | cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz 96 | │ ZeropoolPool │ SyncPoolValue │ SyncPoolNewPointer │ SyncPoolPointer │ 97 | │ sec/op │ sec/op vs base │ sec/op vs base │ sec/op vs base │ 98 | *-12 38.28n ± 2% 63.17n ± 0% +65.00% (p=0.000 n=10) 62.77n ± 2% +63.97% (p=0.000 n=10) 25.99n ± 38% -32.13% (p=0.000 n=10) 99 | ``` 100 | 101 | Note that we're talking about nanoseconds here, and if you found this library you were probably more worried about that extra allocation we save: 102 | 103 | ``` 104 | │ ZeropoolPool │ SyncPoolValue │ SyncPoolNewPointer │ SyncPoolPointer │ 105 | │ B/op │ B/op vs base │ B/op vs base │ B/op vs base │ 106 | *-12 0.00 ± 0% 24.00 ± 0% ? (p=0.000 n=10) 24.00 ± 0% ? (p=0.000 n=10) 0.00 ± 0% ~ (p=1.000 n=10) ¹ 107 | ¹ all samples are equal 108 | 109 | │ ZeropoolPool │ SyncPoolValue │ SyncPoolNewPointer │ SyncPoolPointer │ 110 | │ allocs/op │ allocs/op vs base │ allocs/op vs base │ allocs/op vs base │ 111 | *-12 0.000 ± 0% 1.000 ± 0% ? (p=0.000 n=10) 1.000 ± 0% ? (p=0.000 n=10) 0.000 ± 0% ~ (p=1.000 n=10) ¹ 112 | ¹ all samples are equal 113 | ``` 114 | 115 | [^1]: Some smaller types, like scalar values, can be stored in an interface type without allocation, but you wouldn't use a `sync.Pool` for those, right? 116 | [^2]: [SA6002 ignored in Prometheus' head_append.go](https://github.com/prometheus/prometheus/blob/211ae4f1f0a2cdaae09c4c52735f75345c1817c6/tsdb/head_append.go#L206) 117 | [^3]: [SA6002 ignored in Kubernetes' client.go](https://github.com/kubernetes-sigs/metrics-server/blob/c9bc643883fbb438e2e128caab1e3498f1528cfd/pkg/scraper/client/resource/client.go#L95) 118 | [^4]: [GitHub search for SA6002](https://github.com/search?q=SA6002&type=code) 119 | -------------------------------------------------------------------------------- /pool_test.go: -------------------------------------------------------------------------------- 1 | package zeropool_test 2 | 3 | import ( 4 | "math" 5 | "reflect" 6 | "sync" 7 | "sync/atomic" 8 | "testing" 9 | 10 | "github.com/colega/zeropool" 11 | ) 12 | 13 | func TestPool(t *testing.T) { 14 | t.Run("provides correct values", func(t *testing.T) { 15 | pool := zeropool.New(func() []byte { return make([]byte, 1024) }) 16 | item1 := pool.Get() 17 | assertEqual(t, 1024, len(item1)) 18 | 19 | item2 := pool.Get() 20 | assertEqual(t, 1024, len(item2)) 21 | 22 | pool.Put(item1) 23 | pool.Put(item2) 24 | 25 | item1 = pool.Get() 26 | assertEqual(t, 1024, len(item1)) 27 | 28 | item2 = pool.Get() 29 | assertEqual(t, 1024, len(item2)) 30 | }) 31 | 32 | t.Run("is not racy", func(t *testing.T) { 33 | pool := zeropool.New(func() []byte { return make([]byte, 1024) }) 34 | 35 | const iterations = 1e6 36 | const concurrency = math.MaxUint8 37 | var counter atomic.Int64 38 | 39 | do := make(chan struct{}, 1e6) 40 | for i := 0; i < iterations; i++ { 41 | do <- struct{}{} 42 | } 43 | close(do) 44 | 45 | run := make(chan struct{}) 46 | done := sync.WaitGroup{} 47 | done.Add(concurrency) 48 | for i := 0; i < concurrency; i++ { 49 | go func(worker int) { 50 | <-run 51 | for range do { 52 | item := pool.Get() 53 | item[0] = byte(worker) 54 | counter.Add(1) // Counts and also adds some delay to add raciness. 55 | if item[0] != byte(worker) { 56 | panic("wrong value") 57 | } 58 | pool.Put(item) 59 | } 60 | done.Done() 61 | }(i) 62 | } 63 | close(run) 64 | done.Wait() 65 | t.Logf("Done %d iterations", counter.Load()) 66 | }) 67 | 68 | t.Run("does not allocate", func(t *testing.T) { 69 | pool := zeropool.New(func() []byte { return make([]byte, 1024) }) 70 | // Warm up, this will alloate one slice. 71 | slice := pool.Get() 72 | pool.Put(slice) 73 | 74 | allocs := testing.AllocsPerRun(1000, func() { 75 | slice := pool.Get() 76 | pool.Put(slice) 77 | }) 78 | assertEqualf(t, float64(0), allocs, "Should not allocate.") 79 | }) 80 | 81 | t.Run("zero value is valid", func(t *testing.T) { 82 | var pool zeropool.Pool[[]byte] 83 | slice := pool.Get() 84 | pool.Put(slice) 85 | 86 | allocs := testing.AllocsPerRun(1000, func() { 87 | slice := pool.Get() 88 | pool.Put(slice) 89 | }) 90 | assertEqualf(t, float64(0), allocs, "Should not allocate.") 91 | }) 92 | } 93 | 94 | func BenchmarkZeropoolPool(b *testing.B) { 95 | b.Run("same goroutine", func(b *testing.B) { 96 | pool := zeropool.New(func() []byte { return make([]byte, 1024) }) 97 | 98 | // Warmup 99 | item := pool.Get() 100 | pool.Put(item) 101 | 102 | b.ResetTimer() 103 | for i := 0; i < b.N; i++ { 104 | item := pool.Get() 105 | pool.Put(item) 106 | } 107 | }) 108 | 109 | b.Run("different goroutines", func(b *testing.B) { 110 | pool := zeropool.New(func() []byte { return make([]byte, 1024) }) 111 | 112 | ch := make(chan []byte) 113 | go func() { 114 | for item := range ch { 115 | pool.Put(item) 116 | } 117 | }() 118 | defer close(ch) 119 | 120 | // Warmup. 121 | ch <- pool.Get() 122 | 123 | b.ResetTimer() 124 | for i := 0; i < b.N; i++ { 125 | ch <- pool.Get() 126 | } 127 | }) 128 | 129 | } 130 | 131 | // BenchmarkSyncPoolValue uses sync.Pool to store values, which makes an allocation on each Put call. 132 | func BenchmarkSyncPoolValue(b *testing.B) { 133 | b.Run("same goroutine", func(b *testing.B) { 134 | pool := sync.Pool{New: func() any { 135 | return make([]byte, 1024) 136 | }} 137 | 138 | // Warmup. 139 | item := pool.Get().([]byte) 140 | pool.Put(item) //nolint:staticcheck // This allocates. 141 | 142 | b.ResetTimer() 143 | for i := 0; i < b.N; i++ { 144 | item := pool.Get().([]byte) 145 | pool.Put(item) //nolint:staticcheck // This allocates. 146 | } 147 | }) 148 | 149 | b.Run("different goroutines", func(b *testing.B) { 150 | pool := sync.Pool{New: func() any { 151 | return make([]byte, 1024) 152 | }} 153 | 154 | ch := make(chan []byte) 155 | go func() { 156 | for item := range ch { 157 | pool.Put(item) //nolint:staticcheck // This allocates. 158 | } 159 | }() 160 | defer close(ch) 161 | 162 | // Warmup 163 | ch <- pool.Get().([]byte) 164 | 165 | b.ResetTimer() 166 | for i := 0; i < b.N; i++ { 167 | ch <- pool.Get().([]byte) 168 | } 169 | }) 170 | } 171 | 172 | // BenchmarkSyncPoolNewPointer uses sync.Pool to store pointers, but it calls Put with a new pointer every time. 173 | func BenchmarkSyncPoolNewPointer(b *testing.B) { 174 | b.Run("same goroutine", func(b *testing.B) { 175 | pool := sync.Pool{New: func() any { 176 | v := make([]byte, 1024) 177 | return &v 178 | }} 179 | 180 | // Warmup 181 | item := pool.Get().(*[]byte) 182 | pool.Put(item) 183 | 184 | b.ResetTimer() 185 | for i := 0; i < b.N; i++ { 186 | item := pool.Get().(*[]byte) 187 | buf := *item 188 | pool.Put(&buf) //nolint:staticcheck // New pointer. 189 | } 190 | }) 191 | 192 | b.Run("different goroutines", func(b *testing.B) { 193 | pool := sync.Pool{New: func() any { 194 | v := make([]byte, 1024) 195 | return &v 196 | }} 197 | ch := make(chan []byte) 198 | go func() { 199 | for item := range ch { 200 | pool.Put(&item) //nolint:staticcheck // New pointer. 201 | } 202 | }() 203 | defer close(ch) 204 | 205 | // Warmup 206 | ch <- *(pool.Get().(*[]byte)) 207 | 208 | b.ResetTimer() 209 | for i := 0; i < b.N; i++ { 210 | ch <- *(pool.Get().(*[]byte)) 211 | } 212 | }) 213 | } 214 | 215 | // BenchmarkSyncPoolPointer illustrates the optimal usage of sync.Pool, not always possible. 216 | func BenchmarkSyncPoolPointer(b *testing.B) { 217 | b.Run("same goroutine", func(b *testing.B) { 218 | pool := sync.Pool{New: func() any { 219 | v := make([]byte, 1024) 220 | return &v 221 | }} 222 | 223 | // Warmup 224 | item := pool.Get().(*[]byte) 225 | pool.Put(item) 226 | 227 | b.ResetTimer() 228 | for i := 0; i < b.N; i++ { 229 | item := pool.Get().(*[]byte) 230 | pool.Put(item) 231 | } 232 | }) 233 | 234 | b.Run("different goroutines", func(b *testing.B) { 235 | pool := sync.Pool{New: func() any { 236 | v := make([]byte, 1024) 237 | return &v 238 | }} 239 | 240 | ch := make(chan *[]byte) 241 | go func() { 242 | for item := range ch { 243 | pool.Put(item) 244 | } 245 | }() 246 | defer close(ch) 247 | 248 | // Warmup 249 | ch <- pool.Get().(*[]byte) 250 | 251 | b.ResetTimer() 252 | for i := 0; i < b.N; i++ { 253 | ch <- pool.Get().(*[]byte) 254 | } 255 | }) 256 | } 257 | 258 | func assertEqual(t *testing.T, expected, got interface{}) { 259 | t.Helper() 260 | if !reflect.DeepEqual(expected, got) { 261 | t.Logf("Expected %v, got %v", expected, got) 262 | t.Fail() 263 | } 264 | } 265 | 266 | func assertEqualf(t *testing.T, expected, got interface{}, msg string, args ...any) { 267 | t.Helper() 268 | if !reflect.DeepEqual(expected, got) { 269 | t.Logf("Expected %v, got %v", expected, got) 270 | t.Errorf(msg, args...) 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------