Skip to content

Commit

Permalink
Clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Nov 3, 2023
1 parent 4769cdd commit 77827e4
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 64 deletions.
2 changes: 1 addition & 1 deletion plugins/chop/generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Chop for GeneratorChop {
1.0
};
let cur_value = cur_value * scale;
output[i][j] = cur_value as f32;
output[i][j] = cur_value;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/chop/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl InfoChop for PythonChop {
fn channel(&self, index: usize) -> (String, f32) {
match index {
0 => ("execute_count".to_string(), self.execute_count as f32),
1 => ("offset".to_string(), self.offset as f32),
1 => ("offset".to_string(), self.offset),
_ => panic!("Invalid channel index"),
}
}
Expand Down
14 changes: 7 additions & 7 deletions plugins/dat/filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ impl FilterDat {
output.set_table_size(rows, cols);
for row in 0..rows {
for col in 0..cols {
if let Some(cell) = input.cell(row.clone(), col) {
if let Some(cell) = input.cell(row, col) {
match self.params.case {
FilterType::UpperCamelCase => {
let formatted = to_camel_case(cell, self.params.keep_spaces.clone());
let formatted = to_camel_case(cell, self.params.keep_spaces);
output[[row, col]] = formatted;
}
FilterType::LowerCase => {
let formatted = to_lower_case(cell, self.params.keep_spaces.clone());
let formatted = to_lower_case(cell, self.params.keep_spaces);
output[[row, col]] = formatted;
}
FilterType::UpperCase => {
let formatted = to_upper_case(cell, self.params.keep_spaces.clone());
let formatted = to_upper_case(cell, self.params.keep_spaces);
output[[row, col]] = formatted;
}
}
Expand All @@ -93,15 +93,15 @@ impl FilterDat {
let mut output = output.text();
match self.params.case {
FilterType::UpperCamelCase => {
let formatted = to_camel_case(input.text(), self.params.keep_spaces.clone());
let formatted = to_camel_case(input.text(), self.params.keep_spaces);
output.set_text(&formatted);
}
FilterType::LowerCase => {
let formatted = to_lower_case(input.text(), self.params.keep_spaces.clone());
let formatted = to_lower_case(input.text(), self.params.keep_spaces);
output.set_text(&formatted);
}
FilterType::UpperCase => {
let formatted = to_upper_case(input.text(), self.params.keep_spaces.clone());
let formatted = to_upper_case(input.text(), self.params.keep_spaces);
output.set_text(&formatted);
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/top/cpu-memory-top/src/frame_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ impl FrameQueue {
if let Some(b) = &old_buf {
if b.size() < byte_size || b.size() > byte_size * 2 || b.flags() != flags {
let mut ctx = self.context.lock().unwrap();
return Some(ctx.create_output_buffer(byte_size as usize, flags));
return Some(ctx.create_output_buffer(byte_size, flags));
}
return old_buf;
}
}
let mut ctx = self.context.lock().unwrap();
Some(ctx.create_output_buffer(byte_size as usize, flags))
Some(ctx.create_output_buffer(byte_size, flags))
}

pub fn update_complete(&self, buf_info: BufferInfo) {
Expand Down
2 changes: 1 addition & 1 deletion td-rs-base/src/chop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl ChopInput {

unsafe {
std::slice::from_raw_parts(
*self.input.channelData.offset(index as isize),
*self.input.channelData.add(index),
self.input.numSamples as usize,
)
}
Expand Down
24 changes: 4 additions & 20 deletions td-rs-base/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,7 @@ impl Param for ChopParam {
impl ChopParam {
/// Get the chop input for this parameter, if it exists.
pub fn input(&self) -> Option<&ChopInput> {
if let Some(input) = self.input {
Some(unsafe { ChopInput::ref_cast(&*input) })
} else {
None
}
self.input.map(|input| unsafe { ChopInput::ref_cast(&*input) })
}
}

Expand All @@ -614,11 +610,7 @@ impl Param for SopParam {
impl SopParam {
/// Get the sop input for this parameter, if it exists.
pub fn input(&self) -> Option<&SopInput> {
if let Some(input) = self.input {
Some(unsafe { SopInput::ref_cast(&*input) })
} else {
None
}
self.input.map(|input| unsafe { SopInput::ref_cast(&*input) })
}
}

Expand All @@ -641,11 +633,7 @@ impl Param for TopParam {
impl TopParam {
/// Get the top input for this parameter, if it exists.
pub fn input(&self) -> Option<&crate::top::TopInput> {
if let Some(input) = self.input {
Some(unsafe { crate::top::TopInput::ref_cast(&*input) })
} else {
None
}
self.input.map(|input| unsafe { crate::top::TopInput::ref_cast(&*input) })
}
}

Expand All @@ -668,11 +656,7 @@ impl Param for DatParam {
impl DatParam {
/// Get the dat input for this parameter, if it exists.
pub fn input(&self) -> Option<&crate::dat::DatInput> {
if let Some(input) = self.input {
Some(unsafe { crate::dat::DatInput::ref_cast(&*input) })
} else {
None
}
self.input.map(|input| unsafe { crate::dat::DatInput::ref_cast(&*input) })
}
}

Expand Down
2 changes: 2 additions & 0 deletions td-rs-base/src/sop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_snake_case)]

use crate::cxx::SOP_CustomAttribInfo;
use crate::{cxx, GetInput, OperatorInputs};
use auto_ops::impl_op_ex;
Expand Down
8 changes: 4 additions & 4 deletions td-rs-chop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl<'execute> ChopOutput<'execute> {
}

unsafe {
let channel_ptr = *self.output.channels.offset(index as isize);
std::slice::from_raw_parts(channel_ptr, self.num_samples() as usize)
let channel_ptr = *self.output.channels.add(index);
std::slice::from_raw_parts(channel_ptr, self.num_samples())
}
}

Expand All @@ -74,8 +74,8 @@ impl<'execute> ChopOutput<'execute> {
}

unsafe {
let channel_ptr = *self.output.channels.offset(index as isize);
std::slice::from_raw_parts_mut(channel_ptr, self.num_samples() as usize)
let channel_ptr = *self.output.channels.add(index);
std::slice::from_raw_parts_mut(channel_ptr, self.num_samples())
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions td-rs-dat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'execute> CellType<'execute> for f64 {
let ptr = table.table.as_ptr();

unsafe {
let y = ptr.offset(offset as isize) as *mut f64;
let y = ptr.add(offset) as *mut f64;
*y = out;
}

Expand All @@ -116,7 +116,7 @@ impl<'execute> CellType<'execute> for f64 {
fn set(table: &mut DatTableOutput<Self>, row: usize, col: usize, value: Self) {
let [rows, _] = table.table_size();
let offset = row * rows + col;
table.table[offset] = value.clone();
table.table[offset] = value;
table
.output
.as_mut()
Expand All @@ -138,17 +138,17 @@ impl<'execute> CellType<'execute> for i32 {
let ptr = table.table.as_ptr();

unsafe {
let y = ptr.offset(offset.clone() as isize) as *mut i32;
let y = ptr.add(offset) as *mut i32;
*y = out;
}

&table.table[offset]
}

fn set(table: &mut DatTableOutput<Self>, row: usize, col: usize, value: Self) {
let rows = table.table_size()[0].clone();
let offset = row.clone() * rows + col.clone();
table.table[offset] = value.clone();
let rows = table.table_size()[0];
let offset = row * rows + col;
table.table[offset] = value;
table
.output
.as_mut()
Expand All @@ -158,8 +158,8 @@ impl<'execute> CellType<'execute> for i32 {

impl<'execute> CellType<'execute> for String {
fn get<'a>(table: &'a DatTableOutput<'execute, Self>, row: usize, col: usize) -> &'a Self {
let rows = table.table_size()[0].clone();
let offset = row.clone() * rows + col.clone();
let rows = table.table_size()[0];
let offset = row * rows + col;
let out = unsafe {
let out = table.output.as_ref().getCellString(row as i32, col as i32);
std::ffi::CStr::from_ptr(out).to_str().unwrap()
Expand All @@ -168,7 +168,7 @@ impl<'execute> CellType<'execute> for String {
let ptr = table.table.as_ptr();

unsafe {
let y = ptr.offset(offset.clone() as isize) as *mut &str;
let y = ptr.add(offset) as *mut &str;
*y = out;
}

Expand Down
2 changes: 1 addition & 1 deletion td-rs-derive-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub fn py_op_methods(_attr: TokenStream, item: TokenStream) -> TokenStream {

let generated_functions: Vec<_> = input.items.iter().filter_map(|item| {
if let syn::ImplItem::Method(method) = item {
let has_py_meth = method.attrs.iter().any(|attr| is_py_meth_attr(&attr));
let has_py_meth = method.attrs.iter().any(is_py_meth_attr);
if has_py_meth {
let fn_name = &method.sig.ident;
Some(PyMeth {
Expand Down
8 changes: 4 additions & 4 deletions td-rs-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate proc_macro;

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;


use quote::quote;

Expand Down Expand Up @@ -165,9 +165,9 @@ fn impl_params(input: &DeriveInput) -> TokenStream {

let field_name_upper = format_name(&field_name.to_string());
let default_label = format!("{}", field_name);
let label = label.unwrap_or_else(|| default_label);
let label = label.unwrap_or(default_label);
let default_page = "Custom".to_string();
let page = page.unwrap_or_else(|| default_page);
let page = page.unwrap_or(default_page);
let min = min.unwrap_or(0.0);
let max = max.unwrap_or(1.0);

Expand Down Expand Up @@ -225,5 +225,5 @@ fn capitalize_first(s: &str) -> String {
}

fn remove_underscores(s: &str) -> String {
s.replace("_", "")
s.replace('_', "")
}
2 changes: 1 addition & 1 deletion td-rs-xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::process::Command;

pub use anyhow::Result;

const PLUGIN_HOME: &'static str = "target/plugin";
const PLUGIN_HOME: &str = "target/plugin";

pub fn build(packages: &[&str], args: &[&str]) -> Result<()> {
let package_args = packages.iter().flat_map(|package| ["-p", package]);
Expand Down
26 changes: 13 additions & 13 deletions td-rs-xtask/src/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn install_plugin(
plugin: &str,
_plugin_type: PluginType,
) -> anyhow::Result<()> {
let plugin = &plugin.replace("-", "_");
let plugin = &plugin.replace('-', "_");
let plugin_target_path = plugin_target_path(plugin).join(format!("{plugin}.plugin"));
let td_plugin_folder = &config.macos.plugin_folder;
println!(
Expand Down Expand Up @@ -43,27 +43,27 @@ pub(crate) fn build_plugin(
&["--release", &format!("--target={target}")],
)?;

let plugin = &plugin.replace("-", "_");
let plugin = &plugin.replace('-', "_");
let path = pbxproj_path(plugin);

println!("Writing xcode project to {:?}", path);
write_xcodeproj(&target, &plugin, &plugin_type, &path)?;
write_xcodeproj(target, plugin, &plugin_type, &path)?;
println!("Building xcode project");
build_xcode(config, &plugin)?;
build_xcode(config, plugin)?;
println!("Moving plugin to {:?}", PLUGIN_HOME);
move_plugin(plugin, &path)?;
Ok(())
}

fn move_plugin(plugin: &str, path: &PathBuf) -> anyhow::Result<()> {
fs_extra::dir::remove(&path.parent().unwrap())
fs_extra::dir::remove(path.parent().unwrap())
.context("Could not remove xcode project directory")?;
let plugin_build_path = format!("build/Release/{plugin}.plugin");
let plugin_target_path = plugin_target_path(plugin);
std::fs::create_dir_all(&plugin_target_path).context("Could not create plugin directory")?;
fs_extra::dir::remove(&plugin_target_path.join(format!("{plugin}.plugin")))
fs_extra::dir::remove(plugin_target_path.join(format!("{plugin}.plugin")))
.context("Could not remove plugin directory")?;
fs_extra::dir::move_dir(&plugin_build_path, &plugin_target_path, &CopyOptions::new())
fs_extra::dir::move_dir(plugin_build_path, &plugin_target_path, &CopyOptions::new())
.context("Could not move plugin to target directory")?;
Ok(())
}
Expand Down Expand Up @@ -101,13 +101,13 @@ fn write_xcodeproj(
plugin_type: &PluginType,
path: &PathBuf,
) -> anyhow::Result<()> {
const LIB_KEY: &'static str = "9E4ACB8B299AC54200A2B1CE";
const BUNDLE_KEY: &'static str = "E23329D61DF092AD0002B4FE";
const BUNDLE_CONFIGURATION_KEY: &'static str = "E23329D51DF092AD0002B4FE";
const LIB_KEY: &str = "9E4ACB8B299AC54200A2B1CE";
const BUNDLE_KEY: &str = "E23329D61DF092AD0002B4FE";
const BUNDLE_CONFIGURATION_KEY: &str = "E23329D51DF092AD0002B4FE";

let plugin_type_name = plugin_type.to_short_name();

std::fs::create_dir_all(&path.parent().unwrap())
std::fs::create_dir_all(path.parent().unwrap())
.context("Could not create xcode project directory")?;
let mut project = Value::from_file(format!(
"td-rs-xtask/xcode/{plugin_type_name}/project.pbxproj"
Expand Down Expand Up @@ -135,10 +135,10 @@ fn write_xcodeproj(
.unwrap()
.as_dictionary_mut()
.unwrap();
bundle_config.insert("name".to_string(), Value::String(format!("{plugin}")));
bundle_config.insert("name".to_string(), Value::String(plugin.to_string()));
bundle_config.insert(
"productName".to_string(),
Value::String(format!("{plugin}")),
Value::String(plugin.to_string()),
);
project.to_file_xml(path)?;
Ok(())
Expand Down

0 comments on commit 77827e4

Please sign in to comment.