]> 127.0.0.1 Git - part/.git/commitdiff
1 v0.28.20240721005956
authorqydysky <qydysky@foxmail.com>
Sun, 21 Jul 2024 00:55:00 +0000 (08:55 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 21 Jul 2024 00:55:00 +0000 (08:55 +0800)
websocket/Recoder.go

index 7d7b01898adffb67e915742cf68387f0f0e7f869..db929a03f79c2a7c0e08061bca7912d906585a8f 100644 (file)
@@ -100,10 +100,8 @@ func Play(filePath string) (s *Server, close func()) {
                defer timer.Stop()
 
                var (
-                       cu       atomic.Int64
-                       data     []byte
+                       cu       atomic.Uint64
                        sendData = pslice.New[byte]()
-                       e        error
                )
 
                s.Interface().Pull_tag(map[string]func(any) (disable bool){
@@ -116,7 +114,7 @@ func Play(filePath string) (s *Server, close func()) {
                                                timer.Reset(time.Second)
                                        default:
                                                if d, err := strconv.ParseFloat(data, 64); err == nil && d > 0 {
-                                                       cu.Store(int64(d))
+                                                       cu.Store(uint64(d))
                                                }
                                        }
                                }
@@ -136,21 +134,21 @@ func Play(filePath string) (s *Server, close func()) {
                        sendData.Reset()
                        sendData.Append([]byte("["))
                        for !ctx.Done(sg) {
-                               if data, e = f.ReadUntil([]byte{'\n'}, 70, humanize.MByte); e != nil && !errors.Is(e, io.EOF) {
+                               tmp, e := f.ReadUntil([]byte{'\n'}, 70, humanize.MByte)
+                               if e != nil && !errors.Is(e, io.EOF) {
                                        panic(e)
                                }
-                               if len(data) == 0 {
+                               if len(tmp) == 0 {
                                        return
                                }
 
-                               tIndex := bytes.Index(data, []byte{','})
-                               if d, _ := strconv.ParseFloat(string(data[:tIndex]), 64); d < float64(cu.Load()) {
-                                       danmuIndex := tIndex + bytes.Index(data[tIndex+2:], []byte{','}) + 3
+                               tIndex := bytes.Index(tmp, []byte{','})
+                               if d, _ := strconv.ParseFloat(string(tmp[:tIndex]), 64); d < float64(cu.Load()) {
+                                       danmuIndex := tIndex + bytes.Index(tmp[tIndex+2:], []byte{','}) + 3
                                        if sendData.Size() > 1 {
                                                sendData.Append([]byte(","))
                                        }
-                                       sendData.Append(data[danmuIndex:])
-                                       data = nil
+                                       sendData.Append(tmp[danmuIndex:])
                                } else {
                                        break
                                }