libcamera: controls: Expose string controls as std::string_view
When retrieving the value from a `ControlValue` usually one of two things happen: a small, trivially copyable object is returned by value; or a view into the internal buffer is provided. This is true for everything except strings, which are returned in `std::string`, incurring the overhead of string construction. To guarantee no potentially "expensive" copies, use `std::string_view` pointing to the internal buffer to return the value. This is similar to how other array-like types are returned with a `Span<>`. This is an API break, but its scope is limited to just `properties::Model`. Bug: https://bugs.libcamera.org/show_bug.cgi?id=256 Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -502,7 +502,7 @@ ControlValue CaptureScript::parseScalarControl(const ControlId *id,
|
||||
break;
|
||||
}
|
||||
case ControlTypeString: {
|
||||
value.set<std::string>(repr);
|
||||
value.set<std::string_view>(repr);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -345,7 +345,7 @@ std::string CamApp::cameraName(const Camera *camera)
|
||||
*/
|
||||
const auto &model = props.get(properties::Model);
|
||||
if (model)
|
||||
name += "'" + *model + "' ";
|
||||
name.append("'").append(*model).append("' ");
|
||||
}
|
||||
|
||||
name += "(" + camera->id() + ")";
|
||||
|
||||
@@ -564,7 +564,7 @@ int DNGWriter::write(const char *filename, const Camera *camera,
|
||||
|
||||
const auto &model = cameraProperties.get(properties::Model);
|
||||
if (model) {
|
||||
TIFFSetField(tif, TIFFTAG_MODEL, model->c_str());
|
||||
TIFFSetField(tif, TIFFTAG_MODEL, std::string(*model).c_str());
|
||||
/* \todo set TIFFTAG_UNIQUECAMERAMODEL. */
|
||||
}
|
||||
|
||||
|
||||
@@ -114,8 +114,8 @@ void CameraSelectorDialog::updateCameraInfo(QString cameraId)
|
||||
cameraLocation_->setText("Unknown");
|
||||
}
|
||||
|
||||
const auto &model = properties.get(libcamera::properties::Model)
|
||||
const auto model = properties.get(libcamera::properties::Model)
|
||||
.value_or("Unknown");
|
||||
|
||||
cameraModel_->setText(QString::fromStdString(model));
|
||||
cameraModel_->setText(QString::fromUtf8(model.data(), model.length()));
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ py::object controlValueToPy(const ControlValue &cv)
|
||||
case ControlTypeFloat:
|
||||
return valueOrTuple<float>(cv);
|
||||
case ControlTypeString:
|
||||
return py::cast(cv.get<std::string>());
|
||||
return py::cast(cv.get<std::string_view>());
|
||||
case ControlTypeSize: {
|
||||
const Size *v = reinterpret_cast<const Size *>(cv.data().data());
|
||||
return py::cast(v);
|
||||
@@ -88,7 +88,7 @@ ControlValue pyToControlValue(const py::object &ob, ControlType type)
|
||||
case ControlTypeFloat:
|
||||
return controlValueMaybeArray<float>(ob);
|
||||
case ControlTypeString:
|
||||
return ControlValue(ob.cast<std::string>());
|
||||
return ControlValue(ob.cast<std::string_view>());
|
||||
case ControlTypeRectangle:
|
||||
return controlValueMaybeArray<Rectangle>(ob);
|
||||
case ControlTypeSize:
|
||||
|
||||
Reference in New Issue
Block a user