adding Clone() method
This commit is contained in:
parent
800d55deec
commit
cd58fd5e0e
14
message.go
14
message.go
@ -14,6 +14,20 @@ type Message struct {
|
||||
ClosesChannel bool
|
||||
}
|
||||
|
||||
func (m *Message) Clone() Message {
|
||||
results := Message{
|
||||
Dialect: strings.Clone(m.Dialect),
|
||||
ID: strings.Clone(m.ID),
|
||||
Parameters: make(map[string]string, len(m.Parameters)),
|
||||
Body: strings.Clone(m.Body),
|
||||
ClosesChannel: m.ClosesChannel,
|
||||
}
|
||||
for k, v := range m.Parameters {
|
||||
results.Parameters[strings.Clone(k)] = strings.Clone(v)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
func (m Message) String() string {
|
||||
switch {
|
||||
case m.Chatter():
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package msmsg
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@ -10,6 +11,20 @@ type MessageWithNormalizedInput struct {
|
||||
NormalizedInput string
|
||||
}
|
||||
|
||||
var TheTestObjectsKeys = func() []string {
|
||||
results := make([]string, 0, len(TheTestObjects))
|
||||
for key := range TheTestObjects {
|
||||
results = append(results, key)
|
||||
}
|
||||
return results
|
||||
}()
|
||||
|
||||
func RandomTestObject() MessageWithNormalizedInput {
|
||||
key := TheTestObjectsKeys[rand.Intn(len(TheTestObjectsKeys))]
|
||||
return TheTestObjects[key]
|
||||
|
||||
}
|
||||
|
||||
var TheTestObjects = map[string]MessageWithNormalizedInput{
|
||||
"<dialect ch= '0'>This message is opening this channel.</dialect>": {
|
||||
Message: Message{
|
||||
@ -104,3 +119,17 @@ func TestParseMessage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageClone(b *testing.B) {
|
||||
for b.Loop() {
|
||||
msg := RandomTestObject()
|
||||
msg.Message.Clone()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageParse(b *testing.B) {
|
||||
for b.Loop() {
|
||||
msg := RandomTestObject()
|
||||
ParseMessage(msg.NormalizedInput)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user