[v1,1/3] libcamera: v4l2_subdevice: Remove unnecessary variable
diff mbox series

Message ID 20251218140701.83069-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1,1/3] libcamera: v4l2_subdevice: Remove unnecessary variable
Related show

Commit Message

Barnabás Pőcze Dec. 18, 2025, 2:06 p.m. UTC
`model` is not used, so remove it.

Fixes: 5d2aad02e86d45 ("libcamera: add model() for retrieving model name in V4L2Subdevice")
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/libcamera/v4l2_subdevice.cpp | 1 -
 1 file changed, 1 deletion(-)

Comments

Kieran Bingham Dec. 18, 2025, 4:09 p.m. UTC | #1
Quoting Barnabás Pőcze (2025-12-18 14:07:00)
> Make the `std::regex` object have static lifetime to avoid
> reconstructing it on every call.
> 

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  src/libcamera/v4l2_subdevice.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 00205bc72..5e337a8cc 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -1725,7 +1725,7 @@ const std::string &V4L2Subdevice::model()
>          * an I2C address, and use the full entity name otherwise.
>          */
>         std::string entityName = entity_->name();
> -       std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" };
> +       static const std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" };
>         std::smatch match;
>  
>         if (std::regex_search(entityName, match, i2cRegex))
> -- 
> 2.52.0
>
Barnabás Pőcze Dec. 18, 2025, 4:15 p.m. UTC | #2
Hi

2025. 12. 18. 17:08 keltezéssel, Kieran Bingham írta:
> Quoting Barnabás Pőcze (2025-12-18 14:07:01)
>> There is no reason make a copy of the name, so don't do it,
>> and instead use a reference.
>>
>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>> ---
>>   src/libcamera/v4l2_subdevice.cpp | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
>> index 5e337a8cc..a69de154e 100644
>> --- a/src/libcamera/v4l2_subdevice.cpp
>> +++ b/src/libcamera/v4l2_subdevice.cpp
>> @@ -1724,7 +1724,7 @@ const std::string &V4L2Subdevice::model()
>>           * part of the entity name before the first space if the name contains
>>           * an I2C address, and use the full entity name otherwise.
>>           */
>> -       std::string entityName = entity_->name();
>> +       const std::string &entityName = entity_->name();
> 
> Not a string view? I thought this would be the use case for a read only
> view? Or would that prevent the copy/assignment below?

`std::regex_search()` does not support `std::string_view` natively,
so as far as I'm aware one would have to write:

   std::regex_search(entityName.begin(), entityName.end(), ...)

and `entity_->name()` already returns `const std::string&`, so
there is no copying there. So it would work, but this was less changes.


> 
> But this sounds fine to me.
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
>>          static const std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" };
>>          std::smatch match;
>>   
>> -- 
>> 2.52.0
>>

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index 199424600..00205bc72 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -1728,7 +1728,6 @@  const std::string &V4L2Subdevice::model()
 	std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" };
 	std::smatch match;
 
-	std::string model;
 	if (std::regex_search(entityName, match, i2cRegex))
 		model_ = entityName.substr(0, entityName.find(' '));
 	else