VirtualBox

Changeset 31482 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 9, 2010 12:55:33 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64564
Message:

Main: less string copying with media paths

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31481 r31482  
    481481    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    482482
    483     Utf8Str strConfigFile(aParent->getDefaultMachineFolder());
    484     strConfigFile.append(Utf8StrFmt("%c%s%c%s.xml",
    485                                     RTPATH_DELIMITER,
    486                                     strName.c_str(),
    487                                     RTPATH_DELIMITER,
    488                                     strName.c_str()));
     483    Utf8Str strConfigFile;
     484    aParent->getDefaultMachineFolder(strConfigFile);
     485    strConfigFile.append(RTPATH_DELIMITER);
     486    strConfigFile.append(strName);
     487    strConfigFile.append(RTPATH_DELIMITER);
     488    strConfigFile.append(strName);
     489    strConfigFile.append(".xml");
    489490
    490491    HRESULT rc = initImpl(aParent, strConfigFile);
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31481 r31482  
    30633063 *                      the specified location, and -1 otherwise.
    30643064 */
    3065 HRESULT Medium::compareLocationTo(const char *aLocation, int &aResult)
     3065HRESULT Medium::compareLocationTo(const Utf8Str &strLocation, int &aResult)
    30663066{
    30673067    AutoCaller autoCaller(this);
     
    30763076    if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    30773077    {
    3078         Utf8Str location(aLocation);
     3078        Utf8Str location;
    30793079
    30803080        /* For locations represented by files, append the default path if
    30813081         * only the name is given, and then get the full path. */
    3082         if (!RTPathHavePath(aLocation))
    3083         {
    3084             location = Utf8StrFmt("%s%c%s",
    3085                                   m->pVirtualBox->getDefaultHardDiskFolder().raw(),
    3086                                   RTPATH_DELIMITER,
    3087                                   aLocation);
    3088         }
     3082        if (!RTPathHavePath(strLocation.c_str()))
     3083        {
     3084            m->pVirtualBox->getDefaultHardDiskFolder(location);
     3085            location.append(RTPATH_DELIMITER);
     3086            location.append(strLocation);
     3087        }
     3088        else
     3089            location = strLocation;
    30893090
    30903091        int vrc = m->pVirtualBox->calculateFullPath(location, location);
     
    30983099    }
    30993100    else
    3100         aResult = locationFull.compare(aLocation);
     3101        aResult = locationFull.compare(strLocation);
    31013102
    31023103    return S_OK;
     
    32043205    /* check that our own format supports diffs */
    32053206    if (!(m->formatObj->getCapabilities() & MediumFormatCapabilities_Differencing))
     3207    {
    32063208        /* use the default format if not */
    3207         return m->pVirtualBox->getDefaultHardDiskFormat();
     3209        Utf8Str tmp;
     3210        m->pVirtualBox->getDefaultHardDiskFormat(tmp);
     3211        return tmp;
     3212    }
    32083213
    32093214    /* m->strFormat is const, no need to lock */
     
    33203325        /* append the default folder if no path is given */
    33213326        if (!RTPathHavePath(location.c_str()))
    3322             location = Utf8StrFmt("%s%c%s",
    3323                                   m->pVirtualBox->getDefaultHardDiskFolder().raw(),
    3324                                   RTPATH_DELIMITER,
    3325                                   location.raw());
     3327        {
     3328            Utf8Str tmp;
     3329            m->pVirtualBox->getDefaultHardDiskFolder(tmp);
     3330            tmp.append(RTPATH_DELIMITER);
     3331            tmp.append(location);
     3332            location = tmp;
     3333        }
    33263334
    33273335        /* get the full file name */
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31481 r31482  
    11391139    if (strSettingsFile.isEmpty())
    11401140        /* we use the non-full folder value below to keep the path relative */
    1141         strSettingsFile = getDefaultMachineFolder();
     1141        getDefaultMachineFolder(strSettingsFile);
    11421142
    11431143    strSettingsFile = Utf8StrFmt("%s%c%ls%c%ls.xml",
     
    13781378    Utf8Str format(aFormat);
    13791379    if (format.isEmpty())
    1380         format = getDefaultHardDiskFormat();
     1380        getDefaultHardDiskFormat(format);
    13811381
    13821382    HRESULT rc = E_FAIL;
     
    27452745            const ComObjPtr<Medium> &hd = (*it).second;
    27462746
    2747             HRESULT rc = hd->compareLocationTo(location.c_str(), result);
     2747            HRESULT rc = hd->compareLocationTo(location, result);
    27482748            if (FAILED(rc)) return rc;
    27492749
     
    29792979 * @return
    29802980 */
    2981 Utf8Str VirtualBox::getDefaultMachineFolder() const
     2981void VirtualBox::getDefaultMachineFolder(Utf8Str &str) const
    29822982{
    29832983    AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS);
    2984     return m->pSystemProperties->m->strDefaultMachineFolder;
     2984    str = m->pSystemProperties->m->strDefaultMachineFolder;
    29852985}
    29862986
     
    29902990 * @return
    29912991 */
    2992 Utf8Str VirtualBox::getDefaultHardDiskFolder() const
     2992void VirtualBox::getDefaultHardDiskFolder(Utf8Str &str) const
    29932993{
    29942994    AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS);
    2995     return m->pSystemProperties->m->strDefaultHardDiskFolder;
     2995    str = m->pSystemProperties->m->strDefaultHardDiskFolder;
    29962996}
    29972997
     
    30013001 * @return
    30023002 */
    3003 Utf8Str VirtualBox::getDefaultHardDiskFormat() const
     3003void VirtualBox::getDefaultHardDiskFormat(Utf8Str &str) const
    30043004{
    30053005    AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS);
    3006     return m->pSystemProperties->m->strDefaultHardDiskFormat;
     3006    str = m->pSystemProperties->m->strDefaultHardDiskFormat;
    30073007}
    30083008
  • trunk/src/VBox/Main/include/MediumImpl.h

    r31479 r31482  
    198198    HRESULT saveSettings(settings::Medium &data);
    199199
    200     HRESULT compareLocationTo(const char *aLocation, int &aResult);
     200    HRESULT compareLocationTo(const Utf8Str &strLocation, int &aResult);
    201201
    202202    HRESULT createMediumLockList(bool fFailIfInaccessible,
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31358 r31482  
    242242#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    243243
    244     Utf8Str getDefaultMachineFolder() const;
    245     Utf8Str getDefaultHardDiskFolder() const;
    246     Utf8Str getDefaultHardDiskFormat() const;
     244    void getDefaultMachineFolder(Utf8Str &str) const;
     245    void getDefaultHardDiskFolder(Utf8Str &str) const;
     246    void getDefaultHardDiskFormat(Utf8Str &str) const;
    247247
    248248    /** Returns the VirtualBox home directory */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette