codemaker/source/codemaker/typemanager.cxx |    8 ++---
 cppuhelper/source/typemanager.cxx          |    4 +-
 cppuhelper/source/typemanager.hxx          |    2 -
 include/codemaker/typemanager.hxx          |    4 +-
 include/unoidl/unoidl.hxx                  |    8 ++---
 unoidl/source/legacyprovider.cxx           |    5 +--
 unoidl/source/legacyprovider.hxx           |    2 -
 unoidl/source/sourcefileprovider.cxx       |    5 +--
 unoidl/source/sourcefileprovider.hxx       |    2 -
 unoidl/source/sourceprovider-parser.y      |    4 +-
 unoidl/source/sourcetreeprovider.cxx       |    3 +
 unoidl/source/sourcetreeprovider.hxx       |    2 -
 unoidl/source/unoidl-read.cxx              |   44 ++++++++++++++---------------
 unoidl/source/unoidl-write.cxx             |    2 -
 unoidl/source/unoidl.cxx                   |    7 ++--
 unoidl/source/unoidlprovider.cxx           |   41 +++++++++++++--------------
 unoidl/source/unoidlprovider.hxx           |    2 -
 17 files changed, 75 insertions(+), 70 deletions(-)

New commits:
commit 2d9291b9433c9645b0870525211f74bfb1151555
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Apr 21 12:53:15 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Apr 21 13:53:26 2022 +0200

    use more string_view in unoidl,codemaker
    
    Change-Id: Ibc0624a662c98ef1308a3bb0c7c082935a89a25c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133252
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/codemaker/source/codemaker/typemanager.cxx 
b/codemaker/source/codemaker/typemanager.cxx
index 194840ca9d5b..c684d048782b 100644
--- a/codemaker/source/codemaker/typemanager.cxx
+++ b/codemaker/source/codemaker/typemanager.cxx
@@ -33,15 +33,15 @@ TypeManager::TypeManager(): manager_(new unoidl::Manager) {}
 
 TypeManager::~TypeManager() {}
 
-void TypeManager::loadProvider(OUString const & uri, bool primary) {
+void TypeManager::loadProvider(std::u16string_view uri, bool primary) {
     rtl::Reference< unoidl::Provider > prov(manager_->addProvider(uri));
     if (primary) {
         primaryProviders_.push_back(prov);
     }
 }
 
-bool TypeManager::foundAtPrimaryProvider(OUString const & name) const {
-    if (name.isEmpty()) {
+bool TypeManager::foundAtPrimaryProvider(std::u16string_view name) const {
+    if (name.empty()) {
         return !primaryProviders_.empty();
     }
     for (const rtl::Reference< unoidl::Provider >& xProvider : 
primaryProviders_)
@@ -51,7 +51,7 @@ bool TypeManager::foundAtPrimaryProvider(OUString const & 
name) const {
         }
     }
     if (!manager_->findEntity(name).is()) {
-        throw CannotDumpException("Unknown entity '" + name + "'");
+        throw CannotDumpException(OUString::Concat("Unknown entity '") + name 
+ "'");
     }
     return false;
 }
diff --git a/cppuhelper/source/typemanager.cxx 
b/cppuhelper/source/typemanager.cxx
index 44105df033fa..0b19954f92d5 100644
--- a/cppuhelper/source/typemanager.cxx
+++ b/cppuhelper/source/typemanager.cxx
@@ -2102,7 +2102,7 @@ css::uno::Any 
cppuhelper::TypeManager::getInstantiatedStruct(
     OUString const & name, sal_Int32 separator)
 {
     assert(name.indexOf('<') == separator && separator != -1);
-    rtl::Reference< unoidl::Entity > ent(findEntity(name.copy(0, separator)));
+    rtl::Reference< unoidl::Entity > ent(findEntity(name.subView(0, 
separator)));
     if (!ent.is()
         || (ent->getSort()
             != unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE))
@@ -2289,7 +2289,7 @@ css::uno::Any cppuhelper::TypeManager::getConstant(
 }
 
 rtl::Reference< unoidl::Entity > cppuhelper::TypeManager::findEntity(
-    OUString const & name)
+    std::u16string_view name)
 {
     try {
         return manager_->findEntity(name);
diff --git a/cppuhelper/source/typemanager.hxx 
b/cppuhelper/source/typemanager.hxx
index 28c193191267..615495ca7f80 100644
--- a/cppuhelper/source/typemanager.hxx
+++ b/cppuhelper/source/typemanager.hxx
@@ -115,7 +115,7 @@ private:
         rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
         OUString const & member);
 
-    rtl::Reference< unoidl::Entity > findEntity(OUString const & name);
+    rtl::Reference< unoidl::Entity > findEntity(std::u16string_view name);
 
     rtl::Reference< unoidl::Manager > manager_;
 };
diff --git a/include/codemaker/typemanager.hxx 
b/include/codemaker/typemanager.hxx
index 3e6f67fe4b3f..0fa75caa359c 100644
--- a/include/codemaker/typemanager.hxx
+++ b/include/codemaker/typemanager.hxx
@@ -43,9 +43,9 @@ class TypeManager final : public 
salhelper::SimpleReferenceObject {
 public:
     TypeManager();
 
-    void loadProvider(OUString const & uri, bool primary);
+    void loadProvider(std::u16string_view uri, bool primary);
 
-    bool foundAtPrimaryProvider(OUString const & name) const;
+    bool foundAtPrimaryProvider(std::u16string_view name) const;
 
     codemaker::UnoType::Sort getSort(
         OUString const & name, rtl::Reference< unoidl::Entity > * entity = 
nullptr,
diff --git a/include/unoidl/unoidl.hxx b/include/unoidl/unoidl.hxx
index e2ae024d06f7..50412d599e84 100644
--- a/include/unoidl/unoidl.hxx
+++ b/include/unoidl/unoidl.hxx
@@ -675,7 +675,7 @@ public:
     virtual rtl::Reference< MapCursor > createRootCursor() const = 0;
 
     // throws FileFormatException:
-    virtual rtl::Reference< Entity > findEntity(OUString const & name)
+    virtual rtl::Reference< Entity > findEntity(std::u16string_view name)
         const = 0;
 
 protected:
@@ -689,10 +689,10 @@ public:
     Manager() {}
 
     // throws FileFormatException, NoSuchFileException:
-    rtl::Reference< Provider > addProvider(OUString const & uri);
+    rtl::Reference< Provider > addProvider(std::u16string_view uri);
 
     // throws FileFormatException:
-    rtl::Reference< Entity > findEntity(OUString const & name) const;
+    rtl::Reference< Entity > findEntity(std::u16string_view name) const;
 
     // throws FileFormatException:
     rtl::Reference< MapCursor > createCursor(OUString const & name) const;
@@ -701,7 +701,7 @@ private:
     virtual SAL_DLLPRIVATE ~Manager() noexcept override;
 
     SAL_DLLPRIVATE rtl::Reference< Provider > loadProvider(
-        OUString const & uri);
+        std::u16string_view uri);
 
     mutable osl::Mutex mutex_;
     std::vector< rtl::Reference< Provider > > providers_;
diff --git a/unoidl/source/legacyprovider.cxx b/unoidl/source/legacyprovider.cxx
index ab99fcf59dd1..577febd9c1b0 100644
--- a/unoidl/source/legacyprovider.cxx
+++ b/unoidl/source/legacyprovider.cxx
@@ -813,11 +813,12 @@ rtl::Reference< MapCursor > 
LegacyProvider::createRootCursor() const {
     return new Cursor(&manager_, ucr_, ucr_);
 }
 
-rtl::Reference< Entity > LegacyProvider::findEntity(OUString const & name)
+rtl::Reference< Entity > LegacyProvider::findEntity(std::u16string_view name)
     const
 {
+    OUString s(name);
     return ucr_.isValid()
-        ? readEntity(&manager_, ucr_, ucr_, name.replace('.', '/'), true)
+        ? readEntity(&manager_, ucr_, ucr_, s.replace('.', '/'), true)
         : rtl::Reference< Entity >();
 }
 
diff --git a/unoidl/source/legacyprovider.hxx b/unoidl/source/legacyprovider.hxx
index caa1b38c84a4..8c22dbe0451c 100644
--- a/unoidl/source/legacyprovider.hxx
+++ b/unoidl/source/legacyprovider.hxx
@@ -26,7 +26,7 @@ public:
     virtual rtl::Reference< MapCursor > createRootCursor() const override;
 
     // throws FileFormatException:
-    virtual rtl::Reference< Entity > findEntity(OUString const & name)
+    virtual rtl::Reference< Entity > findEntity(std::u16string_view name)
         const override;
 
 private:
diff --git a/unoidl/source/sourcefileprovider.cxx 
b/unoidl/source/sourcefileprovider.cxx
index 983b7d3c3403..e487fcf47590 100644
--- a/unoidl/source/sourcefileprovider.cxx
+++ b/unoidl/source/sourcefileprovider.cxx
@@ -15,6 +15,7 @@
 
 #include "sourcefileprovider.hxx"
 #include "sourceprovider-scanner.hxx"
+#include <o3tl/string_view.hxx>
 
 namespace unoidl::detail {
 
@@ -105,12 +106,12 @@ rtl::Reference<MapCursor> 
SourceFileProvider::createRootCursor() const {
     return new Cursor(rootMap_);
 }
 
-rtl::Reference<Entity> SourceFileProvider::findEntity(OUString const & name)
+rtl::Reference<Entity> SourceFileProvider::findEntity(std::u16string_view name)
     const
 {
     std::map< OUString, rtl::Reference<Entity> > const * map = &rootMap_;
     for (sal_Int32 i = 0;;) {
-        OUString id(name.getToken(0, '.', i));
+        OUString id(o3tl::getToken(name, 0, '.', i));
         std::map< OUString, rtl::Reference<Entity> >::const_iterator j(
             map->find(id));
         if (j == map->end()) {
diff --git a/unoidl/source/sourcefileprovider.hxx 
b/unoidl/source/sourcefileprovider.hxx
index 52fd32f3c735..6e586294a0c4 100644
--- a/unoidl/source/sourcefileprovider.hxx
+++ b/unoidl/source/sourcefileprovider.hxx
@@ -28,7 +28,7 @@ public:
     virtual rtl::Reference<MapCursor> createRootCursor() const override;
 
     // throws FileFormatException:
-    virtual rtl::Reference<Entity> findEntity(OUString const& name) const 
override;
+    virtual rtl::Reference<Entity> findEntity(std::u16string_view name) const 
override;
 
 private:
     virtual ~SourceFileProvider() noexcept override;
diff --git a/unoidl/source/sourceprovider-parser.y 
b/unoidl/source/sourceprovider-parser.y
index 2c076f08ac70..a6f9722c9d9e 100644
--- a/unoidl/source/sourceprovider-parser.y
+++ b/unoidl/source/sourceprovider-parser.y
@@ -400,7 +400,7 @@ Found findEntity(
                                  + t));
                             return FOUND_ERROR;
                         }
-                        OUString tmpl(typeNucleus.copy(0, i));
+                        std::u16string_view tmpl(typeNucleus.subView(0, i));
                         do {
                             ++i; // skip '<' or ','
                             sal_Int32 j = i;
@@ -3509,7 +3509,7 @@ primaryExpr:
               YYERROR;
           }
           if (ent != nullptr) {
-              OUString id(name.copy(i + 1));
+              std::u16string_view id(name.subView(i + 1));
               // No need to check for enum members here, as they cannot be
               // referenced in expressions by qualified name (TODO: is that 
true?):
               if (ent->entity.is()) {
diff --git a/unoidl/source/sourcetreeprovider.cxx 
b/unoidl/source/sourcetreeprovider.cxx
index fea67405cd54..2f115bef44bf 100644
--- a/unoidl/source/sourcetreeprovider.cxx
+++ b/unoidl/source/sourcetreeprovider.cxx
@@ -231,9 +231,10 @@ rtl::Reference<MapCursor> 
SourceTreeProvider::createRootCursor() const {
     return new Cursor(manager_, uri_);
 }
 
-rtl::Reference<Entity> SourceTreeProvider::findEntity(OUString const & name)
+rtl::Reference<Entity> SourceTreeProvider::findEntity(std::u16string_view 
_name)
     const
 {
+    OUString name(_name);
     std::map< OUString, rtl::Reference<Entity> >::iterator ci(
         cache_.find(name));
     if (ci != cache_.end()) {
diff --git a/unoidl/source/sourcetreeprovider.hxx 
b/unoidl/source/sourcetreeprovider.hxx
index 37bd6baa1286..9b2d6fd55cb9 100644
--- a/unoidl/source/sourcetreeprovider.hxx
+++ b/unoidl/source/sourcetreeprovider.hxx
@@ -28,7 +28,7 @@ public:
     virtual rtl::Reference<MapCursor> createRootCursor() const override;
 
     // throws FileFormatException:
-    virtual rtl::Reference<Entity> findEntity(OUString const& name) const 
override;
+    virtual rtl::Reference<Entity> findEntity(std::u16string_view name) const 
override;
 
 private:
     virtual ~SourceTreeProvider() noexcept override;
diff --git a/unoidl/source/unoidl-read.cxx b/unoidl/source/unoidl-read.cxx
index fcf541612ec5..794bd0b473e7 100644
--- a/unoidl/source/unoidl-read.cxx
+++ b/unoidl/source/unoidl-read.cxx
@@ -84,26 +84,26 @@ OUString getArgumentUri(sal_uInt32 argument) {
     return abs;
 }
 
-OUString decomposeType(
-    OUString const & type, std::size_t * rank,
+std::u16string_view decomposeType(
+    std::u16string_view type, std::size_t * rank,
     std::vector<OUString> * typeArguments, bool * entity)
 {
     assert(rank != nullptr);
     assert(typeArguments != nullptr);
     assert(entity != nullptr);
-    OUString nucl(type);
+    std::u16string_view nucl(type);
     *rank = 0;
     typeArguments->clear();
-    while (nucl.startsWith("[]", &nucl)) {
+    while (o3tl::starts_with(nucl, u"[]", &nucl)) {
         ++*rank;
     }
-    sal_Int32 i = nucl.indexOf('<');
-    if (i != -1) {
-        OUString tmpl(nucl.copy(0, i));
+    size_t i = nucl.find('<');
+    if (i != std::u16string_view::npos) {
+        std::u16string_view tmpl(nucl.substr(0, i));
         do {
             ++i; // skip '<' or ','
-            sal_Int32 j = i;
-            for (sal_Int32 level = 0; j != nucl.getLength(); ++j) {
+            size_t j = i;
+            for (sal_Int32 level = 0; j != nucl.size(); ++j) {
                 sal_Unicode c = nucl[j];
                 if (c == ',') {
                     if (level == 0) {
@@ -118,22 +118,22 @@ OUString decomposeType(
                     --level;
                 }
             }
-            if (j != nucl.getLength()) {
-                typeArguments->push_back(nucl.copy(i, j - i));
+            if (j != nucl.size()) {
+                typeArguments->push_back(OUString(nucl.substr(i, j - i)));
             }
             i = j;
-        } while (i != nucl.getLength() && nucl[i] != '>');
-        assert(i == nucl.getLength() - 1 && nucl[i] == '>');
+        } while (i != nucl.size() && nucl[i] != '>');
+        assert(i == nucl.size() - 1 && nucl[i] == '>');
         assert(!typeArguments->empty());
         nucl = tmpl;
     }
-    assert(!nucl.isEmpty());
-    *entity = nucl != "void" && nucl != "boolean" && nucl != "byte"
-        && nucl != "short" && nucl != "unsigned short" && nucl != "long"
-        && nucl != "unsigned long" && nucl != "hyper"
-        && nucl != "unsigned hyper" && nucl != "float" && nucl != "double"
-        && nucl != "char" && nucl != "string" && nucl != "type"
-        && nucl != "any";
+    assert(!nucl.empty());
+    *entity = nucl != u"void" && nucl != u"boolean" && nucl != u"byte"
+        && nucl != u"short" && nucl != u"unsigned short" && nucl != u"long"
+        && nucl != u"unsigned long" && nucl != u"hyper"
+        && nucl != u"unsigned hyper" && nucl != u"float" && nucl != u"double"
+        && nucl != u"char" && nucl != u"string" && nucl != u"type"
+        && nucl != u"any";
     assert(*entity || typeArguments->empty());
     return nucl;
 }
@@ -204,7 +204,7 @@ void insertEntityDependencies(
 void insertTypeDependency(
     rtl::Reference<unoidl::Manager> const & manager,
     std::map<OUString, Entity>::iterator const & iterator,
-    OUString const & type)
+    std::u16string_view type)
 {
     std::size_t rank;
     std::vector<OUString> args;
@@ -520,7 +520,7 @@ void writeAnnotationsPublished(
     writePublished(entity);
 }
 
-void writeType(OUString const & type) {
+void writeType(std::u16string_view type) {
     std::size_t rank;
     std::vector<OUString> args;
     bool entity;
diff --git a/unoidl/source/unoidl-write.cxx b/unoidl/source/unoidl-write.cxx
index 5ddd98468359..dafca970c246 100644
--- a/unoidl/source/unoidl-write.cxx
+++ b/unoidl/source/unoidl-write.cxx
@@ -394,7 +394,7 @@ void mapEntities(
                     std::map< OUString, Item >::iterator k(map2->find(id));
                     if (k == map2->end()) {
                         rtl::Reference< unoidl::Entity > ent2(
-                            manager->findEntity(t.copy(0, j - 1)));
+                            manager->findEntity(t.subView(0, j - 1)));
                         assert(ent2.is());
                         k = map2->insert(std::make_pair(id, Item(ent2))).first;
                     }
diff --git a/unoidl/source/unoidl.cxx b/unoidl/source/unoidl.cxx
index 749f9afe4f25..5dfce2348d0c 100644
--- a/unoidl/source/unoidl.cxx
+++ b/unoidl/source/unoidl.cxx
@@ -164,7 +164,7 @@ ServiceBasedSingletonEntity::~ServiceBasedSingletonEntity() 
noexcept {}
 
 Provider::~Provider() noexcept {}
 
-rtl::Reference< Provider > Manager::addProvider(OUString const & uri) {
+rtl::Reference< Provider > Manager::addProvider(std::u16string_view uri) {
     rtl::Reference< Provider > p(loadProvider(uri));
     assert(p.is());
     {
@@ -174,7 +174,7 @@ rtl::Reference< Provider > Manager::addProvider(OUString 
const & uri) {
     return p;
 }
 
-rtl::Reference< Entity > Manager::findEntity(OUString const & name) const {
+rtl::Reference< Entity > Manager::findEntity(std::u16string_view name) const {
     //TODO: caching? (here or in cppuhelper::TypeManager?)
     osl::MutexGuard g(mutex_);
     for (auto & i: providers_) {
@@ -194,7 +194,8 @@ rtl::Reference< MapCursor > Manager::createCursor(OUString 
const & name)
 
 Manager::~Manager() noexcept {}
 
-rtl::Reference< Provider > Manager::loadProvider(OUString const & uri) {
+rtl::Reference< Provider > Manager::loadProvider(std::u16string_view _uri) {
+    OUString uri(_uri);
     osl::DirectoryItem item;
     if (osl::DirectoryItem::get(uri, item) == osl::FileBase::E_None) {
         osl::FileStatus status(osl_FileStatus_Mask_Type);
diff --git a/unoidl/source/unoidlprovider.cxx b/unoidl/source/unoidlprovider.cxx
index e7816afdb2be..de158f10b1b2 100644
--- a/unoidl/source/unoidlprovider.cxx
+++ b/unoidl/source/unoidlprovider.cxx
@@ -27,6 +27,7 @@
 #include <sal/types.h>
 #include <salhelper/simplereferenceobject.hxx>
 #include <unoidl/unoidl.hxx>
+#include <o3tl/string_view.hxx>
 
 #include "unoidlprovider.hxx"
 
@@ -203,18 +204,18 @@ bool isIdentifier(std::u16string_view type, bool scoped) {
 }
 
 void checkTypeName(
-    rtl::Reference< MappedFile > const & file, OUString const & type)
+    rtl::Reference< MappedFile > const & file, std::u16string_view type)
 {
-    OUString nucl(type);
+    std::u16string_view nucl(type);
     bool args = false;
-    while (nucl.startsWith("[]", &nucl)) {}
-    sal_Int32 i = nucl.indexOf('<');
-    if (i != -1) {
-        OUString tmpl(nucl.copy(0, i));
+    while (o3tl::starts_with(nucl, u"[]", &nucl)) {}
+    size_t i = nucl.find('<');
+    if (i != std::u16string_view::npos) {
+        std::u16string_view tmpl(nucl.substr(0, i));
         do {
             ++i; // skip '<' or ','
-            sal_Int32 j = i;
-            for (sal_Int32 level = 0; j != nucl.getLength(); ++j) {
+            size_t j = i;
+            for (size_t level = 0; j != nucl.size(); ++j) {
                 sal_Unicode c = nucl[j];
                 if (c == ',') {
                     if (level == 0) {
@@ -229,20 +230,20 @@ void checkTypeName(
                     --level;
                 }
             }
-            if (j != nucl.getLength()) {
-                checkTypeName(file, nucl.copy(i, j - i));
+            if (j != nucl.size()) {
+                checkTypeName(file, nucl.substr(i, j - i));
                 args = true;
             }
             i = j;
-        } while (i != nucl.getLength() && nucl[i] != '>');
-        if (i != nucl.getLength() - 1 || nucl[i] != '>' || !args) {
-            tmpl.clear(); // bad input
+        } while (i != nucl.size() && nucl[i] != '>');
+        if (i != nucl.size() - 1 || nucl[i] != '>' || !args) {
+            tmpl = {}; // bad input
         }
         nucl = tmpl;
     }
     if (isSimpleType(nucl) ? args : !isIdentifier(nucl, true)) {
         throw FileFormatException(
-            file->uri, "UNOIDL format: bad type \"" + type + "\"");
+            file->uri, OUString::Concat("UNOIDL format: bad type \"") + type + 
"\"");
     }
 }
 
@@ -507,7 +508,7 @@ Compare compare(
 
 sal_uInt32 findInMap(
     rtl::Reference< MappedFile > const & file, MapEntry const * mapBegin,
-    sal_uInt32 mapSize, OUString const & name, sal_Int32 nameOffset,
+    sal_uInt32 mapSize, std::u16string_view name, sal_Int32 nameOffset,
     sal_Int32 nameLength)
 {
     if (mapSize == 0) {
@@ -1348,21 +1349,21 @@ rtl::Reference< MapCursor > 
UnoidlProvider::createRootCursor() const {
         rtl::Reference<UnoidlModuleEntity>(), map_);
 }
 
-rtl::Reference< Entity > UnoidlProvider::findEntity(OUString const & name) 
const
+rtl::Reference< Entity > UnoidlProvider::findEntity(std::u16string_view name) 
const
 {
     NestedMap map(map_);
     bool cgroup = false;
     for (sal_Int32 i = 0;;) {
-        sal_Int32 j = name.indexOf('.', i);
-        if (j == -1) {
-            j = name.getLength();
+        size_t j = name.find('.', i);
+        if (j == std::u16string_view::npos) {
+            j = name.size();
         }
         sal_Int32 off = findInMap(
             file_, map.map.begin, map.map.size, name, i, j - i);
         if (off == 0) {
             return rtl::Reference< Entity >();
         }
-        if (j == name.getLength()) {
+        if (j == name.size()) {
             return cgroup
                 ? rtl::Reference< Entity >()
                 : readEntity(file_, off, std::set(map.trace));
diff --git a/unoidl/source/unoidlprovider.hxx b/unoidl/source/unoidlprovider.hxx
index 734f8592b814..244bd26f3513 100644
--- a/unoidl/source/unoidlprovider.hxx
+++ b/unoidl/source/unoidlprovider.hxx
@@ -41,7 +41,7 @@ public:
     virtual rtl::Reference< MapCursor > createRootCursor() const override;
 
     // throws FileFormatException:
-    virtual rtl::Reference< Entity > findEntity(OUString const & name)
+    virtual rtl::Reference< Entity > findEntity(std::u16string_view name)
         const override;
 
 private:

Reply via email to