Skip to content

Change the parameter types of ParamValues's methods to avoid expensive conversion #8612

@kawadakk

Description

@kawadakk

Describe the bug

The parameter types of ParamValues::{get_placeholders_with_values,verify} could be changed to avoid expensive conversion on the caller side.

impl ParamValues {
    pub fn verify(&self, expect: &Vec<DataType>) -> Result<()>;
}

Receiving &[DataType] instead of &Vec<DataType> will allow the callers to pass an arbitrary slice without cloning it to a temporary Vec first. Clippy has a lint for this: ptr_arg

impl ParamValues {
    pub fn get_placeholders_with_values(
        &self,
        id: &String,
        data_type: &Option<DataType>,
    ) -> Result<ScalarValue>;
}

&String -> &str: ptr_arg likewise.

Receiving Option<&DataType> instead of &Option<DataType> will allow the callers to avoid cloning when they only have &DataType at hand. If the callers have &Option<DataType>, they will have to call Option::as_ref, but the performance cost of this conversion is negligible. There's a work-in-progress Clippy lint for this: rust-lang/rust-clippy#11463

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions