From c360f248f7017de41139147d9e3661c3edd1abe1 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 18 Jan 2025 18:16:48 +0000 Subject: [PATCH] Might as well compile these once and only once --- dlna/contenddirectoryservice.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/dlna/contenddirectoryservice.go b/dlna/contenddirectoryservice.go index 902cc570b..b7865ff72 100644 --- a/dlna/contenddirectoryservice.go +++ b/dlna/contenddirectoryservice.go @@ -29,6 +29,22 @@ type contentDirectoryService struct { upnp.Eventing } +var filesRegex *regroup.ReGroup +var artistRegex *regroup.ReGroup +var albumRegex *regroup.ReGroup +var genresRegex *regroup.ReGroup +var recentRegex *regroup.ReGroup +var playlistRegex *regroup.ReGroup + +func init() { + filesRegex = regroup.MustCompile("\\/Music\\/Files[\\/]?((?P.+))?") + artistRegex = regroup.MustCompile("\\/Music\\/Artists[\\/]?(?P[^\\/]+)?[\\/]?(?[^\\/]+)?[\\/]?(?[^\\/]+)?") + albumRegex = regroup.MustCompile("\\/Music\\/Albums[\\/]?(?P[^\\/]+)?[\\/]?(?[^\\/]+)?") + genresRegex = regroup.MustCompile("\\/Music\\/Genres[\\/]?(?P[^\\/]+)?[\\/]?(?P[^/]+)?[\\/]?(?P[^\\/]+)?") + recentRegex = regroup.MustCompile("\\/Music\\/Recently Added[\\/]?(?P[^\\/]+)?") + playlistRegex = regroup.MustCompile("\\/Music\\/Playlist[\\/]?(?P[^\\/]+)?[\\/]?(?P[^\\/]+)?") +} + func (cds *contentDirectoryService) updateIDString() string { return fmt.Sprintf("%d", uint32(os.Getpid())) } @@ -90,13 +106,6 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret [] return ret, nil } - filesRegex := regroup.MustCompile("\\/Music\\/Files[\\/]?((?P.+))?") - artistRegex := regroup.MustCompile("\\/Music\\/Artists[\\/]?(?P[^\\/]+)?[\\/]?(?[^\\/]+)?[\\/]?(?[^\\/]+)?") - albumRegex := regroup.MustCompile("\\/Music\\/Albums[\\/]?(?P[^\\/]+)?[\\/]?(?[^\\/]+)?") - genresRegex := regroup.MustCompile("\\/Music\\/Genres[\\/]?(?P[^\\/]+)?[\\/]?(?P[^/]+)?[\\/]?(?P[^\\/]+)?") - recentRegex := regroup.MustCompile("\\/Music\\/Recently Added[\\/]?(?P[^\\/]+)?") - playlistRegex := regroup.MustCompile("\\/Music\\/Playlist[\\/]?(?P[^\\/]+)?[\\/]?(?P[^\\/]+)?") - if o.Path == "/Music" { ret = append(ret, cds.cdsObjectToUpnpavObject(object{Path: "/Music/Files"}, true, host)) ret = append(ret, cds.cdsObjectToUpnpavObject(object{Path: "/Music/Artists"}, true, host))