[vlc-commits] [Git][videolan/vlc][master] 3 commits: adaptive: use the reference when reading XML attributes

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu May 18 15:30:51 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
0eb760d5 by Steve Lhomme at 2023-05-18T15:17:42+00:00
adaptive: use the reference when reading XML attributes

This avoids allocations and copies for nothing.

- - - - -
344f941d by Steve Lhomme at 2023-05-18T15:17:42+00:00
dash: use a static array of strings

- - - - -
a69d76ea by Steve Lhomme at 2023-05-18T15:17:42+00:00
adaptive: use const strings to find a string inside another

- - - - -


5 changed files:

- modules/demux/adaptive/tools/Helper.cpp
- modules/demux/adaptive/tools/Helper.h
- modules/demux/dash/DASHManager.cpp
- modules/demux/dash/mpd/IsoffMainParser.cpp
- modules/demux/smooth/playlist/SmoothParser.cpp


Changes:

=====================================
modules/demux/adaptive/tools/Helper.cpp
=====================================
@@ -80,11 +80,15 @@ bool Helper::icaseEquals(std::string str1, std::string str2)
     return str1 == str2;
 }
 
-bool Helper::ifind(std::string haystack, std::string needle)
+bool Helper::ifind(const std::string & haystack, const std::string & needle)
 {
-    transform(haystack.begin(), haystack.end(), haystack.begin(), toupper);
-    transform(needle.begin(), needle.end(), needle.begin(), toupper);
-    return haystack.find(needle) != std::string::npos;
+    return std::search(
+        haystack.cbegin(), haystack.cend(),
+        needle.cbegin(),   needle.cend(),
+        [](unsigned char ch1, unsigned char ch2) {
+            return toupper(ch1) == toupper(ch2);
+        }
+    ) != haystack.end();
 }
 
 std::list<std::string> Helper::tokenize(const std::string &str, char c)


=====================================
modules/demux/adaptive/tools/Helper.h
=====================================
@@ -37,7 +37,7 @@ namespace adaptive
             static std::string getDirectoryPath (const std::string &path);
             static std::string getFileExtension (const std::string &uri);
             static bool        icaseEquals     (std::string str1, std::string str2);
-            static bool        ifind            (std::string haystack, std::string needle);
+            static bool        ifind            (const std::string & haystack, const std::string & needle);
             static std::list<std::string> tokenize(const std::string &, char);
             static std::string & rtrim(std::string &, const std::string &);
             static std::string & ltrim(std::string &, const std::string &);


=====================================
modules/demux/dash/DASHManager.cpp
=====================================
@@ -167,7 +167,7 @@ int DASHManager::doControl(int i_query, va_list args)
 
 bool DASHManager::isDASH(xml::Node *root)
 {
-    const std::string namespaces[] = {
+    static const std::string namespaces[] = {
         "urn:mpeg:mpegB:schema:DASH:MPD:DIS2011",
         "urn:mpeg:schema:dash:mpd:2011",
         "urn:mpeg:DASH:schema:MPD:2011",
@@ -179,7 +179,7 @@ bool DASHManager::isDASH(xml::Node *root)
     if(root->getName() != "MPD")
         return false;
 
-    std::string ns = root->getAttributeValue("xmlns");
+    const std::string &ns = root->getAttributeValue("xmlns");
     for( size_t i=0; i<ARRAY_SIZE(namespaces); i++ )
     {
         if ( adaptive::Helper::ifind(ns, namespaces[i]) )


=====================================
modules/demux/dash/mpd/IsoffMainParser.cpp
=====================================
@@ -250,7 +250,7 @@ size_t IsoffMainParser::parseSegmentTemplate(MPD *mpd, Node *templateNode, Segme
     if(templateNode->hasAttribute("initialization")) /* /!\ != Initialization */
     {
         SegmentTemplateInit *initTemplate;
-        std::string initurl = templateNode->getAttributeValue("initialization");
+        const std::string &initurl = templateNode->getAttributeValue("initialization");
         if(!initurl.empty() && (initTemplate = new (std::nothrow) SegmentTemplateInit(mediaTemplate, info)))
         {
             initTemplate->setSourceUrl(initurl);
@@ -317,7 +317,7 @@ void    IsoffMainParser::parseAdaptationSets  (MPD *mpd, Node *periodNode, BaseP
         Node *role = DOMHelper::getFirstChildElementByName((*it), "Role");
         if(role && role->hasAttribute("schemeIdUri") && role->hasAttribute("value"))
         {
-            std::string uri = role->getAttributeValue("schemeIdUri");
+            const std::string &uri = role->getAttributeValue("schemeIdUri");
             if(uri == "urn:mpeg:dash:role:2011")
             {
                 const std::string &rolevalue = role->getAttributeValue("value");
@@ -462,13 +462,13 @@ size_t IsoffMainParser::parseSegmentList(MPD *mpd, Node * segListNode, SegmentIn
                 if(!seg)
                     continue;
 
-                std::string mediaUrl = segmentURL->getAttributeValue("media");
+                const std::string &mediaUrl = segmentURL->getAttributeValue("media");
                 if(!mediaUrl.empty())
                     seg->setSourceUrl(mediaUrl);
 
                 if(segmentURL->hasAttribute("mediaRange"))
                 {
-                    std::string range = segmentURL->getAttributeValue("mediaRange");
+                    const std::string &range = segmentURL->getAttributeValue("mediaRange");
                     size_t pos = range.find("-");
                     seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
                 }
@@ -499,7 +499,7 @@ void IsoffMainParser::parseInitSegment(Node *initNode, Initializable<InitSegment
 
     if(initNode->hasAttribute("range"))
     {
-        std::string range = initNode->getAttributeValue("range");
+        const std::string &range = initNode->getAttributeValue("range");
         size_t pos = range.find("-");
         seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str()));
     }


=====================================
modules/demux/smooth/playlist/SmoothParser.cpp
=====================================
@@ -238,7 +238,7 @@ static void ParseStreamIndex(BasePeriod *period, Node *streamIndexNode, unsigned
             adaptSet->addAttribute(new TimescaleAttr(timescale));
         }
 
-        const std::string url = streamIndexNode->getAttributeValue("Url");
+        const std::string &url = streamIndexNode->getAttributeValue("Url");
         if(!url.empty())
         {
             /* SmoothSegment is a template holder */
@@ -252,7 +252,7 @@ static void ParseStreamIndex(BasePeriod *period, Node *streamIndexNode, unsigned
             }
 
             unsigned nextid = 1;
-            const std::string type = streamIndexNode->getAttributeValue("Type");
+            const std::string &type = streamIndexNode->getAttributeValue("Type");
             std::vector<Node *> qualLevels = DOMHelper::getElementByTagName(streamIndexNode, "QualityLevel", true);
             std::vector<Node *>::const_iterator it;
             for(it = qualLevels.begin(); it != qualLevels.end(); ++it)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ce7b337398dc980c8de51867efb9d7bad169d3b9...a69d76eafc6153e7fef7534f54c22f4447782cd9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ce7b337398dc980c8de51867efb9d7bad169d3b9...a69d76eafc6153e7fef7534f54c22f4447782cd9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list