gorush: do less copying in queueNotification (#370)

The PushNotification object is quite big (772 bytes on AMD64),
so avoid doing too many copying without a need.

Collect pointers and do copying only when sending into a channel.

Found using https://go-critic.github.io/overview#rangeValCopy-ref

Linter output:
```
$GOPATH/src/github.com/appleboy/gorush/gorush/worker.go:38:2: rangeValCopy: each iteration copies 772 bytes (consider pointers or indexing)
$GOPATH/src/github.com/appleboy/gorush/gorush/worker.go:53:2: rangeValCopy: each iteration copies 772 bytes (consider pointers or indexing)
```
This commit is contained in:
Iskander (Alex) Sharipov 2018-09-17 07:55:23 +01:00 committed by Bo-Yi Wu
parent 313544bde6
commit d275ddbccb
1 changed files with 4 additions and 3 deletions

View File

@ -34,8 +34,9 @@ func startWorker() {
func queueNotification(req RequestPush) (int, []LogPushEntry) { func queueNotification(req RequestPush) (int, []LogPushEntry) {
var count int var count int
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
newNotification := []PushNotification{} newNotification := []*PushNotification{}
for _, notification := range req.Notifications { for i := range req.Notifications {
notification := &req.Notifications[i]
switch notification.Platform { switch notification.Platform {
case PlatFormIos: case PlatFormIos:
if !PushConf.Ios.Enabled { if !PushConf.Ios.Enabled {
@ -56,7 +57,7 @@ func queueNotification(req RequestPush) (int, []LogPushEntry) {
notification.log = &log notification.log = &log
notification.AddWaitCount() notification.AddWaitCount()
} }
QueueNotification <- notification QueueNotification <- *notification
count += len(notification.Tokens) count += len(notification.Tokens)
// Count topic message // Count topic message
if notification.To != "" { if notification.To != "" {