Skip to content

Commit

Permalink
Add new license to NOTICE file
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyisaev2 committed Dec 20, 2024
1 parent dfba480 commit ffd9659
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 102 deletions.
25 changes: 25 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ BSD 3-Clause License:
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MIT License:

* ./app/server/conversion/strftime.go:

MIT License

Copyright (c) 2020 Phus Lu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
===============================================================================

Please see the accompanying LICENSE file for details relating to the Apache License, Version 2.0.
81 changes: 14 additions & 67 deletions app/server/conversion/converters_unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ func (collectionUnsafe) DateToString() ValuePtrConverter[time.Time, string] {
return dateToStringConverterUnsafe{}
}

func (collectionUnsafe) TimestampToString(utc bool) ValuePtrConverter[time.Time, string] {
if utc {
return timestampToStringConverterUTCUnsafe{}
}

return timestampToStringConverterNaive{}
}

func absInt(x int) int {
if x < 0 {
return -x
Expand Down Expand Up @@ -71,9 +79,11 @@ func (dateToStringConverterUnsafe) Convert(in *time.Time) (string, error) {

type timestampToStringConverterUTCUnsafe struct{}

func (timestampToStringConverterUTCUnsafe) Convert(in *time.Time) (string, error) {
func (timestampToStringConverterUTCUnsafe) Convert(src *time.Time) (string, error) {
utc := src.UTC()

buf := make([]byte, 0, 32)
year, month, day := in.Date()
year, month, day := utc.Date()

// year

Expand Down Expand Up @@ -115,7 +125,7 @@ func (timestampToStringConverterUTCUnsafe) Convert(in *time.Time) (string, error
// T
buf = append(buf, byte('T'))

hour, minutes, seconds := in.Clock()
hour, minutes, seconds := utc.Clock()

// hours

Expand Down Expand Up @@ -147,7 +157,7 @@ func (timestampToStringConverterUTCUnsafe) Convert(in *time.Time) (string, error

// nanoseconds

nanoseconds := in.Nanosecond()
nanoseconds := utc.Nanosecond()
if nanoseconds > 0 {
buf = append(buf, byte('.'))

Expand All @@ -160,66 +170,3 @@ func (timestampToStringConverterUTCUnsafe) Convert(in *time.Time) (string, error

return unsafe.String(p, len(buf)), nil
}

const tab = "00010203040506070809" +
"10111213141516171819" +
"20212223242526272829" +
"30313233343536373839" +
"40414243444546474849" +
"50515253545556575859" +
"60616263646566676869" +
"70717273747576777879" +
"80818283848586878889" +
"90919293949596979899"

func formatNanoseconds(buf []byte, ns int) []byte {
// fast transformation of nanoseconds
var tmp [9]byte
b := ns % 100 * 2
tmp[8] = tab[b+1]
tmp[7] = tab[b]
ns /= 100
b = ns % 100 * 2
tmp[6] = tab[b+1]
tmp[5] = tab[b]
ns /= 100
b = ns % 100 * 2
tmp[4] = tab[b+1]
tmp[3] = tab[b]
ns /= 100
b = ns % 100 * 2
tmp[2] = tab[b+1]
tmp[1] = tab[b]
tmp[0] = byte(ns/100) + '0'

// check for trailing zeroes
i := 8
for ; i >= 0; i-- {
if tmp[i] != '0' {
break
}
}

buf = append(buf, tmp[:i+1]...)

return buf
}

func digitsInNumber(n int) int {
if n < 0 {
n = -n
}

if n == 0 {
return 1
}

digits := 0

for n > 0 {
digits++
n /= 10
}

return digits
}
49 changes: 49 additions & 0 deletions app/server/conversion/strftime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2020 Phus Lu. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the NOTICE file.

package conversion

const tab = "00010203040506070809" +
"10111213141516171819" +
"20212223242526272829" +
"30313233343536373839" +
"40414243444546474849" +
"50515253545556575859" +
"60616263646566676869" +
"70717273747576777879" +
"80818283848586878889" +
"90919293949596979899"

func formatNanoseconds(buf []byte, ns int) []byte {
// fast transformation of nanoseconds
var tmp [9]byte
b := ns % 100 * 2

Check failure on line 21 in app/server/conversion/strftime.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)
tmp[8] = tab[b+1]
tmp[7] = tab[b]
ns /= 100
b = ns % 100 * 2
tmp[6] = tab[b+1]
tmp[5] = tab[b]
ns /= 100
b = ns % 100 * 2
tmp[4] = tab[b+1]
tmp[3] = tab[b]
ns /= 100
b = ns % 100 * 2
tmp[2] = tab[b+1]
tmp[1] = tab[b]
tmp[0] = byte(ns/100) + '0'

// check for trailing zeroes
i := 8
for ; i >= 0; i-- {
if tmp[i] != '0' {
break
}
}

buf = append(buf, tmp[:i+1]...)

return buf
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ require (
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/paulmach/orb v0.11.1 // indirect
github.com/phuslu/fasttime v1.0.2
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJ
github.com/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU=
github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
github.com/phuslu/fasttime v1.0.2 h1:gmD27yB6vnQuhk4vtmoBOmjaXsF+wwmyjMtayoHHUko=
github.com/phuslu/fasttime v1.0.2/go.mod h1:1zflhZFowg3RSL0IpmWQ0AprKCKbTRKV9PEpVXDBZ7A=
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ=
Expand Down
32 changes: 0 additions & 32 deletions tools/misc/bench/benchmark_time_formatting_test.go

This file was deleted.

0 comments on commit ffd9659

Please sign in to comment.