[RFC,0/8] libcamera: Use std::string_view
mbox series

Message ID 20241215230206.11002-1-laurent.pinchart@ideasonboard.com
Headers show
Series
  • libcamera: Use std::string_view
Related show

Message

Laurent Pinchart Dec. 15, 2024, 11:01 p.m. UTC
Hello,

This patch series contains a bunch of changes I've had in my tree for
some time. As a similar change was recently proposed ("[RFC PATCH v1]
treewide: Prefer `std::string_view` over `const std::string&` in
parameters"), I decided to clean my branch and post it as a base for
discussions.

After investigating string usage in C++ for a while, I'm convinced about
the fact that it's a mess more than the value of std::string_view. The
class isn't entirely bad, but it suffers from some limitations that make
it painful to use until C++26. I tried to document usage guidelines in
the coding style document (1/8) and found that rules were not easy to
express.

Some of the limitations can be worked around, as shown by patch 2/8.
Patches 3/8 to 8/8 then start exploring more efficient string handling
through the libcamera code base, with some changes that look quite fine,
and some that are more problematic.

My main issue with the string usage guidelines is perhaps that the best
class to use depends on the internal implementation of a function, which
is clearly problematic when designing stable APIs. I'll let everybody
read the series and share their opinion.

Laurent Pinchart (8):
  Documentation: coding-style: Document usage of classes for strings
  libcamera: base: utils: Add string_view concatenation operators
  libcamera: base: file: Fix string usage in class API
  libcamera: base: log: Use std::string_view
  libcamera: base: utils: Use std::string_view
  libcamera: Update string usage in internal APIs
  [DNI] libcamera: Use std::string_view in controls
  [DNI] libcamera: yaml_parser: Replace std::string reference with
    std::string_view

 Documentation/coding-style.rst                | 98 +++++++++++++++++++
 include/libcamera/base/file.h                 |  6 +-
 include/libcamera/base/log.h                  |  3 +-
 include/libcamera/base/utils.h                | 62 ++++++++++--
 include/libcamera/control_ids.h.in            |  3 +-
 include/libcamera/controls.h                  | 21 ++--
 .../internal/camera_sensor_properties.h       |  4 +-
 include/libcamera/internal/converter.h        |  3 +-
 .../internal/converter/converter_v4l2_m2m.h   |  3 +-
 .../libcamera/internal/device_enumerator.h    |  8 +-
 include/libcamera/internal/formats.h          |  3 +-
 include/libcamera/internal/ipa_module.h       |  3 +-
 include/libcamera/internal/ipa_proxy.h        |  7 +-
 include/libcamera/internal/media_device.h     |  9 +-
 include/libcamera/internal/pipeline_handler.h |  7 +-
 .../internal/software_isp/software_isp.h      |  4 +-
 include/libcamera/internal/sysfs.h            |  3 +-
 include/libcamera/internal/v4l2_device.h      |  3 +-
 include/libcamera/internal/v4l2_subdevice.h   |  3 +-
 include/libcamera/internal/v4l2_videodevice.h |  7 +-
 include/libcamera/internal/yaml_parser.h      |  2 +-
 src/apps/cam/capture_script.h                 |  3 +-
 src/gstreamer/gstlibcamera-controls.cpp.in    | 21 ++--
 src/libcamera/base/file.cpp                   | 14 +--
 src/libcamera/base/log.cpp                    | 31 +++---
 src/libcamera/base/meson.build                | 12 +++
 src/libcamera/base/utils.cpp                  | 14 +--
 src/libcamera/control_ids.cpp.in              |  4 +-
 src/libcamera/controls.cpp                    | 15 ++-
 src/libcamera/device_enumerator.cpp           | 10 +-
 src/libcamera/formats.cpp                     |  2 +-
 src/libcamera/ipa_module.cpp                  |  2 +-
 src/libcamera/ipa_proxy.cpp                   |  8 +-
 src/libcamera/media_device.cpp                | 16 +--
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp  |  3 +-
 src/libcamera/pipeline_handler.cpp            |  6 +-
 .../sensor/camera_sensor_properties.cpp       |  4 +-
 src/libcamera/software_isp/software_isp.cpp   |  3 +-
 src/libcamera/sysfs.cpp                       | 10 +-
 src/libcamera/v4l2_device.cpp                 |  2 +-
 src/libcamera/v4l2_subdevice.cpp              |  3 +-
 src/libcamera/v4l2_videodevice.cpp            |  7 +-
 src/libcamera/yaml_parser.cpp                 |  2 +-
 test/camera/camera_reconfigure.cpp            |  2 +-
 test/hotplug-cameras.cpp                      |  3 +-
 test/utils.cpp                                | 34 +++++++
 46 files changed, 352 insertions(+), 141 deletions(-)


base-commit: 8e15010b7dfa9c2a68dd57f924b5603784be0e09