A lil optimize
This commit is contained in:
@@ -15,6 +15,10 @@ func (c *GSM7Coder) Encode(s string, buf *bytes.Buffer) error {
|
|||||||
bitshift byte = 0
|
bitshift byte = 0
|
||||||
leap, shift bool
|
leap, shift bool
|
||||||
)
|
)
|
||||||
|
tbw := len(utf8) * 7 / 8
|
||||||
|
if buf.Available() < tbw {
|
||||||
|
buf.Grow(tbw)
|
||||||
|
}
|
||||||
|
|
||||||
for index, septet := range utf8 {
|
for index, septet := range utf8 {
|
||||||
if septet > 0b01111111 {
|
if septet > 0b01111111 {
|
||||||
|
@@ -147,12 +147,12 @@ func TestGSM7DecodeSimpleASCIIString(t *testing.T) {
|
|||||||
|
|
||||||
// region insertat
|
// region insertat
|
||||||
func TestInsertAtBeginning(t *testing.T) {
|
func TestInsertAtBeginning(t *testing.T) {
|
||||||
data := []byte{2, 3, 4, 0}
|
data := []byte{2, 3, 4, 0}
|
||||||
InsertAt(&data, 0, 1)
|
InsertAt(&data, 0, 1)
|
||||||
expected := []byte{1, 2, 3, 4}
|
expected := []byte{1, 2, 3, 4}
|
||||||
if !bytes.Equal(data, expected) {
|
if !bytes.Equal(data, expected) {
|
||||||
t.Errorf("expected %v, got %v", expected, data)
|
t.Errorf("expected %v, got %v", expected, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertInMiddle(t *testing.T) {
|
func TestInsertInMiddle(t *testing.T) {
|
||||||
@@ -174,13 +174,13 @@ func TestInsertAtEnd(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexOutOfBounds(t *testing.T) {
|
func TestIndexOutOfBounds(t *testing.T) {
|
||||||
data := []byte{2, 3, 4}
|
data := []byte{2, 3, 4}
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r == nil {
|
if r := recover(); r == nil {
|
||||||
t.Errorf("The code did not panic")
|
t.Errorf("The code did not panic")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
InsertAt(&data, 4, 5)
|
InsertAt(&data, 4, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNegativeIndex(t *testing.T) {
|
func TestNegativeIndex(t *testing.T) {
|
||||||
@@ -194,12 +194,12 @@ func TestNegativeIndex(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMaintainsOrderAfterInsertion(t *testing.T) {
|
func TestMaintainsOrderAfterInsertion(t *testing.T) {
|
||||||
data := []byte{2, 3, 4, 0}
|
data := []byte{2, 3, 4, 0}
|
||||||
InsertAt(&data, 1, 1)
|
InsertAt(&data, 1, 1)
|
||||||
expected := []byte{2, 1, 3, 4}
|
expected := []byte{2, 1, 3, 4}
|
||||||
if !bytes.Equal(data, expected) {
|
if !bytes.Equal(data, expected) {
|
||||||
t.Errorf("expected %v, got %v", expected, data)
|
t.Errorf("expected %v, got %v", expected, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaintainsLength(t *testing.T) {
|
func TestMaintainsLength(t *testing.T) {
|
||||||
@@ -251,4 +251,4 @@ func BenchmarkGSM7EncodeComplex8nASCIIString(b *testing.B) {
|
|||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
coder.Encode(input, &buf)
|
coder.Encode(input, &buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user