Skip to content

Commit cc7fcb7

Browse files
committed
[ntuple] Replace all const string & with string_view in fn parameters
1 parent 8a60d4a commit cc7fcb7

21 files changed

Lines changed: 120 additions & 117 deletions

tree/ntuple/inc/ROOT/RField.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private:
185185
ROOT::DescriptorId_t
186186
LookupMember(const ROOT::RNTupleDescriptor &desc, std::string_view memberName, ROOT::DescriptorId_t classFieldId);
187187
/// Sets fStagingClass according to the given name and version
188-
void SetStagingClass(const std::string &className, unsigned int classVersion);
188+
void SetStagingClass(std::string_view className, unsigned int classVersion);
189189
/// If there are rules with inputs (source members), create the staging area according to the TClass instance
190190
/// that corresponds to the on-disk field.
191191
void PrepareStagingArea(const std::vector<const TSchemaRule *> &rules, const ROOT::RNTupleDescriptor &desc,
@@ -555,7 +555,7 @@ namespace Internal {
555555
/// type renormalization of the demangled type name T. The failure case, however, needs to additionally check for
556556
/// ROOT-specific special cases.
557557
template <class T>
558-
bool IsMatchingFieldType(const std::string &actualTypeName)
558+
bool IsMatchingFieldType(std::string_view actualTypeName)
559559
{
560560
return IsMatchingFieldType(actualTypeName, ROOT::RField<T>::TypeName(), typeid(T));
561561
}

tree/ntuple/inc/ROOT/RFieldBase.hxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void CallCommitClusterOnField(RFieldBase &);
6262
void CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t firstEntry = 0);
6363
void CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &);
6464
ROOT::RResult<std::unique_ptr<ROOT::RFieldBase>>
65-
CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options,
65+
CallFieldBaseCreate(std::string_view fieldName, std::string_view typeName, const ROOT::RCreateFieldOptions &options,
6666
const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId);
6767

6868
} // namespace Internal
@@ -97,7 +97,7 @@ class RFieldBase {
9797
friend void Internal::CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t);
9898
friend void Internal::CallConnectPageSourceOnField(RFieldBase &, ROOT::Internal::RPageSource &);
9999
friend ROOT::RResult<std::unique_ptr<ROOT::RFieldBase>>
100-
Internal::CallFieldBaseCreate(const std::string &fieldName, const std::string &typeName,
100+
Internal::CallFieldBaseCreate(std::string_view fieldName, std::string_view typeName,
101101
const ROOT::RCreateFieldOptions &options, const ROOT::RNTupleDescriptor *desc,
102102
ROOT::DescriptorId_t fieldId);
103103

@@ -566,7 +566,7 @@ protected:
566566
/// normalized type name and type alias.
567567
/// `desc` and `fieldId` must be passed if `options.fEmulateUnknownTypes` is true, otherwise they can be left blank.
568568
static RResult<std::unique_ptr<RFieldBase>>
569-
Create(const std::string &fieldName, const std::string &typeName, const ROOT::RCreateFieldOptions &options,
569+
Create(std::string_view fieldName, std::string_view typeName, const ROOT::RCreateFieldOptions &options,
570570
const ROOT::RNTupleDescriptor *desc, ROOT::DescriptorId_t fieldId);
571571

572572
public:
@@ -605,12 +605,11 @@ public:
605605
/// Factory method to create a field from a certain type given as string.
606606
/// Note that the provided type name must be a valid C++ type name. Template arguments of templated types
607607
/// must be type names or integers (e.g., no expressions).
608-
static RResult<std::unique_ptr<RFieldBase>>
609-
Create(const std::string &fieldName, const std::string &typeName);
608+
static RResult<std::unique_ptr<RFieldBase>> Create(std::string_view fieldName, std::string_view typeName);
610609

611610
/// Checks if the given type is supported by RNTuple. In case of success, the result vector is empty.
612611
/// Otherwise there is an error record for each failing subfield (subtype).
613-
static std::vector<RCheckResult> Check(const std::string &fieldName, const std::string &typeName);
612+
static std::vector<RCheckResult> Check(std::string_view fieldName, std::string_view typeName);
614613

615614
/// Generates an object of the field type and allocates new initialized memory according to the type.
616615
/// Implemented at the end of this header because the implementation is using RField<T>::TypeName()

tree/ntuple/inc/ROOT/RFieldUtils.hxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ namespace Internal {
2727
/// template arguments (hence "Prefix").
2828
/// Furthermore, if the type is a C-style array, rules are applied to the base type and the C style array
2929
/// is then mapped to an std::array.
30-
std::string GetCanonicalTypePrefix(const std::string &typeName);
30+
std::string GetCanonicalTypePrefix(std::string_view typeName);
3131

3232
/// Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
33-
std::string GetRenormalizedTypeName(const std::string &metaNormalizedName);
33+
std::string GetRenormalizedTypeName(std::string_view metaNormalizedName);
3434

3535
/// Given a type info ask ROOT meta to demangle it, then renormalize the resulting type name for RNTuple. Useful to
3636
/// ensure that e.g. fundamental types are normalized to the type used by RNTuple (e.g. int -> std::int32_t).
@@ -42,18 +42,18 @@ std::string GetRenormalizedTypeName(const std::type_info &ti);
4242
/// to ensure correct reconstruction of objects from disk.
4343
/// If the function returns true, renormalizedAlias contains the RNTuple normalized name that should be used as
4444
/// type alias.
45-
bool NeedsMetaNameAsAlias(const std::string &metaNormalizedName, std::string &renormalizedAlias,
45+
bool NeedsMetaNameAsAlias(std::string_view metaNormalizedName, std::string &renormalizedAlias,
4646
bool isArgInTemplatedUserClass = false /* used in recursion */);
4747

4848
/// Applies all RNTuple type normalization rules except typedef resolution.
49-
std::string GetNormalizedUnresolvedTypeName(const std::string &origName);
49+
std::string GetNormalizedUnresolvedTypeName(std::string_view origName);
5050

5151
/// Appends 'll' or 'ull' to the where necessary and strips the suffix if not needed.
52-
std::string GetNormalizedInteger(const std::string &intTemplateArg);
52+
std::string GetNormalizedInteger(std::string_view intTemplateArg);
5353
std::string GetNormalizedInteger(long long val);
5454
std::string GetNormalizedInteger(unsigned long long val);
55-
long long ParseIntTypeToken(const std::string &intToken);
56-
unsigned long long ParseUIntTypeToken(const std::string &uintToken);
55+
long long ParseIntTypeToken(std::string_view intToken);
56+
unsigned long long ParseUIntTypeToken(std::string_view uintToken);
5757

5858
/// Possible settings for the "rntuple.streamerMode" class attribute in the dictionary.
5959
enum class ERNTupleSerializationMode {

tree/ntuple/inc/ROOT/RFieldVisitor.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ The functions in this class format strings which are displayed by RNTupleReader:
253253
class RNTupleFormatter {
254254
public:
255255
// Can abbreviate long strings, e.g. ("ExampleString" , space= 8) => "Examp..."
256-
static std::string FitString(const std::string &str, int availableSpace);
256+
static std::string FitString(std::string_view str, int availableSpace);
257257
};
258258

259259
} // namespace Internal

tree/ntuple/inc/ROOT/RMiniFile.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ private:
197197
/// Writes a TKey including the data record, given by buffer, into fFile; returns the file offset to the payload.
198198
/// The payload is already compressed
199199
std::uint64_t WriteKey(const void *buffer, std::size_t nbytes, std::size_t len, std::int64_t offset = -1,
200-
std::uint64_t directoryOffset = 100, const std::string &className = "",
201-
const std::string &objectName = "", const std::string &title = "");
200+
std::uint64_t directoryOffset = 100, std::string_view className = "",
201+
std::string_view objectName = "", std::string_view title = "");
202202
/// Reserves an RBlob opaque key as data record and returns the offset of the record. If keyBuffer is specified,
203203
/// it must be written *before* the returned offset. (Note that the array type is purely documentation, the
204204
/// argument is actually just a pointer.)

tree/ntuple/inc/ROOT/RNTupleDescriptor.hxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,22 +1537,22 @@ public:
15371537
fField.fProjectionSourceId = id;
15381538
return *this;
15391539
}
1540-
RFieldDescriptorBuilder &FieldName(const std::string &fieldName)
1540+
RFieldDescriptorBuilder &FieldName(std::string_view fieldName)
15411541
{
15421542
fField.fFieldName = fieldName;
15431543
return *this;
15441544
}
1545-
RFieldDescriptorBuilder &FieldDescription(const std::string &fieldDescription)
1545+
RFieldDescriptorBuilder &FieldDescription(std::string_view fieldDescription)
15461546
{
15471547
fField.fFieldDescription = fieldDescription;
15481548
return *this;
15491549
}
1550-
RFieldDescriptorBuilder &TypeName(const std::string &typeName)
1550+
RFieldDescriptorBuilder &TypeName(std::string_view typeName)
15511551
{
15521552
fField.fTypeName = typeName;
15531553
return *this;
15541554
}
1555-
RFieldDescriptorBuilder &TypeAlias(const std::string &typeAlias)
1555+
RFieldDescriptorBuilder &TypeAlias(std::string_view typeAlias)
15561556
{
15571557
fField.fTypeAlias = typeAlias;
15581558
return *this;
@@ -1723,12 +1723,12 @@ public:
17231723
fExtraTypeInfo.fTypeVersion = typeVersion;
17241724
return *this;
17251725
}
1726-
RExtraTypeInfoDescriptorBuilder &TypeName(const std::string &typeName)
1726+
RExtraTypeInfoDescriptorBuilder &TypeName(std::string_view typeName)
17271727
{
17281728
fExtraTypeInfo.fTypeName = typeName;
17291729
return *this;
17301730
}
1731-
RExtraTypeInfoDescriptorBuilder &Content(const std::string &content)
1731+
RExtraTypeInfoDescriptorBuilder &Content(std::string_view content)
17321732
{
17331733
fExtraTypeInfo.fContent = content;
17341734
return *this;

tree/ntuple/inc/ROOT/RNTupleMetrics.hxx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ private:
5959
bool fIsEnabled = false;
6060

6161
public:
62-
RNTuplePerfCounter(const std::string &name, const std::string &unit, const std::string &desc)
63-
: fName(name), fUnit(unit), fDescription(desc) {}
62+
RNTuplePerfCounter(std::string_view name, std::string_view unit, std::string_view desc)
63+
: fName(name), fUnit(unit), fDescription(desc)
64+
{
65+
}
6466
virtual ~RNTuplePerfCounter();
6567
void Enable() { fIsEnabled = true; }
6668
bool IsEnabled() const { return fIsEnabled; }
@@ -86,7 +88,7 @@ private:
8688
std::int64_t fCounter = 0;
8789

8890
public:
89-
RNTuplePlainCounter(const std::string &name, const std::string &unit, const std::string &desc)
91+
RNTuplePlainCounter(std::string_view name, std::string_view unit, std::string_view desc)
9092
: RNTuplePerfCounter(name, unit, desc)
9193
{
9294
}
@@ -113,8 +115,10 @@ private:
113115
std::atomic<std::int64_t> fCounter{0};
114116

115117
public:
116-
RNTupleAtomicCounter(const std::string &name, const std::string &unit, const std::string &desc)
117-
: RNTuplePerfCounter(name, unit, desc) { }
118+
RNTupleAtomicCounter(std::string_view name, std::string_view unit, std::string_view desc)
119+
: RNTuplePerfCounter(name, unit, desc)
120+
{
121+
}
118122

119123
R__ALWAYS_INLINE
120124
void Inc() {
@@ -175,8 +179,8 @@ private:
175179
const MetricFunc_t fFunc;
176180

177181
public:
178-
RNTupleCalcPerf(const std::string &name, const std::string &unit, const std::string &desc,
179-
RNTupleMetrics &metrics, MetricFunc_t &&func)
182+
RNTupleCalcPerf(std::string_view name, std::string_view unit, std::string_view desc, RNTupleMetrics &metrics,
183+
MetricFunc_t &&func)
180184
: RNTuplePerfCounter(name, unit, desc), fMetrics(metrics), fFunc(std::move(func))
181185
{
182186
}
@@ -211,7 +215,7 @@ When printing, the value is converted from ticks to nanoseconds.
211215
template <typename BaseCounterT>
212216
class RNTupleTickCounter : public BaseCounterT {
213217
public:
214-
RNTupleTickCounter(const std::string &name, const std::string &unit, const std::string &desc)
218+
RNTupleTickCounter(std::string_view name, std::string_view unit, std::string_view desc)
215219
: BaseCounterT(name, unit, desc)
216220
{
217221
R__ASSERT(unit == "ns");
@@ -294,10 +298,10 @@ private:
294298
std::string fName;
295299
bool fIsEnabled = false;
296300

297-
bool Contains(const std::string &name) const;
301+
bool Contains(std::string_view name) const;
298302

299303
public:
300-
explicit RNTupleMetrics(const std::string &name) : fName(name) {}
304+
explicit RNTupleMetrics(std::string_view name) : fName(name) {}
301305
RNTupleMetrics(const RNTupleMetrics &other) = delete;
302306
RNTupleMetrics & operator=(const RNTupleMetrics &other) = delete;
303307
RNTupleMetrics(RNTupleMetrics &&other) = default;
@@ -306,7 +310,7 @@ public:
306310

307311
// TODO(jblomer): return a reference
308312
template <typename CounterPtrT, class... Args>
309-
CounterPtrT MakeCounter(const std::string &name, Args&&... args)
313+
CounterPtrT MakeCounter(std::string_view name, Args &&...args)
310314
{
311315
R__ASSERT(!Contains(name));
312316
auto counter = std::make_unique<std::remove_pointer_t<CounterPtrT>>(name, std::forward<Args>(args)...);
@@ -323,7 +327,7 @@ public:
323327

324328
void ObserveMetrics(RNTupleMetrics &observee);
325329

326-
void Print(std::ostream &output, const std::string &prefix = "") const;
330+
void Print(std::ostream &output, std::string_view prefix = "") const;
327331
void Enable();
328332
bool IsEnabled() const { return fIsEnabled; }
329333
};

tree/ntuple/inc/ROOT/RNTupleProcessor.hxx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private:
5959

6060
public:
6161
RNTupleOpenSpec(std::string_view n, TDirectory *s) : fNTupleName(n), fStorage(s) {}
62-
RNTupleOpenSpec(std::string_view n, const std::string &s) : fNTupleName(n), fStorage(s) {}
62+
RNTupleOpenSpec(std::string_view n, std::string_view s) : fNTupleName(n), fStorage(std::string(s)) {}
6363

6464
std::unique_ptr<ROOT::Internal::RPageSource> CreatePageSource() const;
6565
};
@@ -314,7 +314,7 @@ protected:
314314
///
315315
/// In case the field was already present in the entry, the index of the existing field is returned.
316316
virtual Internal::RNTupleProcessorEntry::FieldIndex_t
317-
AddFieldToEntry(const std::string &fieldName, const std::string &typeName, void *valuePtr,
317+
AddFieldToEntry(std::string_view fieldName, std::string_view typeName, void *valuePtr,
318318
const Internal::RNTupleProcessorProvenance &provenance) = 0;
319319

320320
/////////////////////////////////////////////////////////////////////////////
@@ -385,7 +385,7 @@ public:
385385
/// invalid data. After passing a pointer to `RequestField`, we *strongly* recommend only accessing its data through
386386
/// the interface of the returned `RNTupleProcessorOptionalPtr`, to ensure that only valid data can be read.
387387
template <typename T>
388-
RNTupleProcessorOptionalPtr<T> RequestField(const std::string &fieldName, void *valuePtr = nullptr)
388+
RNTupleProcessorOptionalPtr<T> RequestField(std::string_view fieldName, void *valuePtr = nullptr)
389389
{
390390
Initialize(fEntry);
391391
std::string typeName{};
@@ -412,7 +412,7 @@ public:
412412
/// invalid data. After passing a pointer to `RequestField`, we *strongly* recommend only accessing its data through
413413
/// the interface of the returned `RNTupleProcessorOptionalPtr`, to ensure that only valid data can be read.
414414
RNTupleProcessorOptionalPtr<void>
415-
RequestField(const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr)
415+
RequestField(std::string_view fieldName, std::string_view typeName, void *valuePtr = nullptr)
416416
{
417417
Initialize(fEntry);
418418
auto fieldIdx = AddFieldToEntry(fieldName, typeName, valuePtr, Internal::RNTupleProcessorProvenance());
@@ -590,7 +590,7 @@ private:
590590
/// \return The newly created field.
591591
/// \throws ROOT::RException In case the requested field cannot be found on disk.
592592
std::unique_ptr<ROOT::RFieldBase>
593-
CreateAndConnectField(const std::string &qualifiedFieldName, const std::string &typeName);
593+
CreateAndConnectField(std::string_view qualifiedFieldName, std::string_view typeName);
594594

595595
/////////////////////////////////////////////////////////////////////////////
596596
/// \brief Initialize the processor by creating an (initially empty) `fEntry`, or setting an existing one.
@@ -631,7 +631,7 @@ private:
631631
///
632632
/// \sa RNTupleProcessor::AddFieldToEntry()
633633
Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(
634-
const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr,
634+
std::string_view fieldName, std::string_view typeName, void *valuePtr = nullptr,
635635
const Internal::RNTupleProcessorProvenance &provenance = Internal::RNTupleProcessorProvenance()) final;
636636

637637
/////////////////////////////////////////////////////////////////////////////
@@ -726,7 +726,7 @@ private:
726726
///
727727
/// \sa RNTupleProcessor::AddFieldToEntry()
728728
Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(
729-
const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr,
729+
std::string_view fieldName, std::string_view typeName, void *valuePtr = nullptr,
730730
const Internal::RNTupleProcessorProvenance &provenance = Internal::RNTupleProcessorProvenance()) final;
731731

732732
/////////////////////////////////////////////////////////////////////////////
@@ -826,7 +826,7 @@ private:
826826
///
827827
/// \sa RNTupleProcessor::AddFieldToEntry()
828828
Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(
829-
const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr,
829+
std::string_view fieldName, std::string_view typeName, void *valuePtr = nullptr,
830830
const Internal::RNTupleProcessorProvenance &provenance = Internal::RNTupleProcessorProvenance()) final;
831831

832832
/////////////////////////////////////////////////////////////////////////////

tree/ntuple/inc/ROOT/RNTupleProcessorEntry.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private:
4141

4242
public:
4343
RNTupleProcessorProvenance() = default;
44-
RNTupleProcessorProvenance(const std::string &provenance) : fProvenance(provenance) {}
44+
RNTupleProcessorProvenance(std::string_view provenance) : fProvenance(provenance) {}
4545

4646
/////////////////////////////////////////////////////////////////////////////
4747
/// \brief Get the full processor provenance, in the form of "x.y.z".
@@ -53,12 +53,12 @@ public:
5353
/// \param[in] processorName Name of the processor to add.
5454
///
5555
/// \return The updated provenance.
56-
RNTupleProcessorProvenance Evolve(const std::string &processorName) const
56+
RNTupleProcessorProvenance Evolve(std::string_view processorName) const
5757
{
5858
if (fProvenance.empty())
5959
return RNTupleProcessorProvenance(processorName);
6060

61-
return RNTupleProcessorProvenance(fProvenance + "." + processorName);
61+
return RNTupleProcessorProvenance(fProvenance + "." + std::string(processorName));
6262
}
6363

6464
/////////////////////////////////////////////////////////////////////////////
@@ -173,7 +173,7 @@ public:
173173
/// \param[in] provenance Processor provenance of the field.
174174
///
175175
/// \return The field index of the newly added field.
176-
FieldIndex_t AddField(const std::string &qualifiedFieldName, std::unique_ptr<ROOT::RFieldBase> field, void *valuePtr,
176+
FieldIndex_t AddField(std::string_view qualifiedFieldName, std::unique_ptr<ROOT::RFieldBase> field, void *valuePtr,
177177
const RNTupleProcessorProvenance &provenance);
178178

179179
/////////////////////////////////////////////////////////////////////////////

tree/ntuple/inc/ROOT/RNTupleSerialize.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public:
222222
static std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer);
223223
static std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t &val);
224224

225-
static std::uint32_t SerializeString(const std::string &val, void *buffer);
225+
static std::uint32_t SerializeString(std::string_view val, void *buffer);
226226
static RResult<std::uint32_t> DeserializeString(const void *buffer, std::uint64_t bufSize, std::string &val);
227227

228228
/// While we could just interpret the enums as ints, we make the translation explicit
@@ -313,7 +313,7 @@ public:
313313

314314
// Helper functions to (de-)serialize the streamer info type extra information
315315
static std::string SerializeStreamerInfos(const StreamerInfoMap_t &infos);
316-
static RResult<StreamerInfoMap_t> DeserializeStreamerInfos(const std::string &extraTypeInfoContent);
316+
static RResult<StreamerInfoMap_t> DeserializeStreamerInfos(std::string_view extraTypeInfoContent);
317317
}; // class RNTupleSerializer
318318

319319
} // namespace Internal

0 commit comments

Comments
 (0)