[SERVER-67455] Refactor std::string casts in PlanCacheSizeParameter::parse Created: 22/Jun/22  Updated: 06/Dec/22  Resolved: 28/Jun/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Jennifer Peshansky (Inactive) Assignee: Backlog - Query Execution
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Participants:

 Description   

Currently, in PlanCacheSizeParameter::parse in src/mongo/db/query/plan_cache_size_parameter.cpp, we take an std::string reference as input and use it to match against a regular expression. We also need to do a lot of std::string conversions on the output.

However, we don't really need std::string.  matchView will accept a StringData as input. Then the std::stod can be changed to exploit our knowledge of m[1]'s format.
We know it's digits, a dot, and then maybe more digits.

The parseUnitString function should just be changed to take StringData.

double size;
invariant(!std::from_chars<double>( 
    m[1].begin(), m[1].end(), size, 
    std::chars_format::fixed).ec);
auto statusWithUnit = parseUnitString(m[2]); 

We will use an invariant instead of uassert because it would indicate that our compiled-in regex was wrong, in that it didn't have the right captures to produce a valid fixed point number.


Generated at Thu Feb 08 06:08:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.