[MDEV-20453] add class similar to std::string_view (non owning string reference) Created: 2019-08-30  Updated: 2022-02-03  Resolved: 2022-02-03

Status: Closed
Project: MariaDB Server
Component/s: Server, Storage Engine - InnoDB
Fix Version/s: N/A

Type: Task Priority: Major
Reporter: Eugene Kosov (Inactive) Assignee: Eugene Kosov (Inactive)
Resolution: Won't Do Votes: 0
Labels: None


 Description   

Class is basically:

class string_view {
  const char *string;
  size_t length;
};

It's intended to replace all naked char * and const std::string:: & in functions arguments.
string_view is better because of a clear semantics: non-owning string. When you see a member or variable const char *smth; you can't say whether it own its buffer or not. For argument you don't know whether ownership was transferred to function or not. Similar to return char * from function.

string_view makes code easier to read. Also it has begin(), end() member which allows it's data to be used in range-for loops.

https://en.cppreference.com/w/cpp/string/basic_string_view



 Comments   
Comment by Marko Mäkelä [ 2020-07-15 ]

It seems that the function fsp_path_to_space_name() is initially accessing one byte before the start of the string, in the first iteration of string_view::rfind() with the default parameter pos=npos, tripping AddressSanitizer in many tests. I reverted the change due to this. Please fix and test with ASAN.

Comment by Marko Mäkelä [ 2021-10-01 ]

The originally found issue may have been resolved by MDEV-25312, which removed the data member fil_space_t::name.

I think that there needs to be some measurable benefit from such refactoring. I see that we currently use std::string (and are unnecessarily copying some data) in file_name_t::name and renamed_spaces. We could make those point directly to the redo log parse buffer. The data would only have to be copied at the end of each non-final recv_sys_t::apply() before the underlying buffer would be invalidated by recv_sys_t::free(). In that way, we would avoid copying any file name strings when only one recovery batch is needed.

Comment by Marko Mäkelä [ 2022-02-03 ]

I think that this basically already exists as LEX_STRING and LEX_CSTRING. We perhaps should not develop several ways of doing the same thing, and I am afraid that there would be strong opposition if the existing classes were renamed or refactored.

Generated at Thu Feb 08 08:59:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.