Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcd0d1e

Browse files
author
Davide Faconti
committed
reduce potential memory allocations using string_view
1 parent b051715 commit fcd0d1e

File tree

5 files changed

+1361
-29
lines changed

5 files changed

+1361
-29
lines changed

docs/tutorial_B_node_parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace BT{
9898

9999
// This template specialization is needed if you want
100100
// to AUTOMATICALLY convert a NodeParameter into a Pose2D
101-
template <> Pose2D BT::convertFromString(const std::string& key)
101+
template <> Pose2D BT::convertFromString(const StringView& key)
102102
{
103103
// Three real numbers separated by semicolons.
104104
// You may use <boost/algorithm/string/split.hpp> if you prefer

include/behaviortree_cpp/basic_types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdexcept>
77
#include <vector>
88
#include <sstream>
9+
#include "behaviortree_cpp/string_view.hpp"
910

1011
namespace BT
1112
{
@@ -60,8 +61,10 @@ enum SuccessPolicy
6061
SUCCEED_ON_ALL
6162
};
6263

64+
typedef nonstd::string_view StringView;
65+
6366
template <typename T>
64-
T convertFromString(const std::string& str);
67+
T convertFromString(const StringView& str);
6568

6669
//------------------------------------------------------------------
6770

@@ -79,8 +82,9 @@ const char* toStr(const BT::NodeType& type);
7982

8083
std::ostream& operator<<(std::ostream& os, const BT::NodeType& type);
8184

85+
8286
// small utility, unless you want to use <boost/algorithm/string.hpp>
83-
std::vector<std::string> splitString(const std::string& strToSplit, char delimeter);
87+
std::vector<StringView> splitString(const StringView& strToSplit, char delimeter);
8488
}
8589

8690
#endif // BT_BASIC_TYPES_H

0 commit comments

Comments
 (0)