Skip to content

Commit 8fa97d0

Browse files
committed
[rust] Micro optimization in the strings usage and other minor issues
1 parent 20348a7 commit 8fa97d0

File tree

9 files changed

+28
-30
lines changed

9 files changed

+28
-30
lines changed

rust/src/chrome.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,19 @@ impl SeleniumManager for ChromeManager {
249249
),
250250
(
251251
BrowserPath::new(MACOS, STABLE),
252-
r#"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"#,
252+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
253253
),
254254
(
255255
BrowserPath::new(MACOS, BETA),
256-
r#"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta"#,
256+
"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
257257
),
258258
(
259259
BrowserPath::new(MACOS, DEV),
260-
r#"/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev"#,
260+
"/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev",
261261
),
262262
(
263263
BrowserPath::new(MACOS, NIGHTLY),
264-
r#"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"#,
264+
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
265265
),
266266
(BrowserPath::new(LINUX, STABLE), "/usr/bin/google-chrome"),
267267
(BrowserPath::new(LINUX, BETA), "/usr/bin/google-chrome-beta"),

rust/src/edge.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ impl SeleniumManager for EdgeManager {
138138
),
139139
(
140140
BrowserPath::new(MACOS, STABLE),
141-
r#"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"#,
141+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
142142
),
143143
(
144144
BrowserPath::new(MACOS, BETA),
145-
r#"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta"#,
145+
"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta",
146146
),
147147
(
148148
BrowserPath::new(MACOS, DEV),
149-
r#"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"#,
149+
"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev",
150150
),
151151
(
152152
BrowserPath::new(MACOS, NIGHTLY),
153-
r#"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary"#,
153+
"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary",
154154
),
155155
(BrowserPath::new(LINUX, STABLE), "/usr/bin/microsoft-edge"),
156156
(
@@ -504,7 +504,7 @@ impl SeleniumManager for EdgeManager {
504504
.to_string()
505505
} else {
506506
format!(
507-
r#"Microsoft\Edge\Application\{}\msedge.exe"#,
507+
r"Microsoft\Edge\Application\{}\msedge.exe",
508508
self.get_browser_version()
509509
)
510510
};

rust/src/files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub fn uncompress_sfx(compressed_file: &str, target: &Path, log: &Logger) -> Res
165165

166166
let zip_parent_str = path_to_string(zip_parent);
167167
let target_str = path_to_string(target);
168-
let core_str = format!(r#"{}\core"#, zip_parent_str);
168+
let core_str = format!(r"{}\core", zip_parent_str);
169169
log.trace(format!(
170170
"Moving extracted files and folders from {} to {}",
171171
core_str, target_str

rust/src/firefox.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,23 @@ impl SeleniumManager for FirefoxManager {
163163
),
164164
(
165165
BrowserPath::new(MACOS, STABLE),
166-
r#"/Applications/Firefox.app/Contents/MacOS/firefox"#,
166+
"/Applications/Firefox.app/Contents/MacOS/firefox",
167167
),
168168
(
169169
BrowserPath::new(MACOS, BETA),
170-
r#"/Applications/Firefox.app/Contents/MacOS/firefox"#,
170+
"/Applications/Firefox.app/Contents/MacOS/firefox",
171171
),
172172
(
173173
BrowserPath::new(MACOS, DEV),
174-
r#"/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox"#,
174+
"/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox",
175175
),
176176
(
177177
BrowserPath::new(MACOS, NIGHTLY),
178-
r#"/Applications/Firefox Nightly.app/Contents/MacOS/firefox"#,
178+
"/Applications/Firefox Nightly.app/Contents/MacOS/firefox",
179179
),
180180
(
181181
BrowserPath::new(MACOS, ESR),
182-
r#"/Applications/Firefox.app/Contents/MacOS/firefox"#,
182+
"/Applications/Firefox.app/Contents/MacOS/firefox",
183183
),
184184
(BrowserPath::new(LINUX, STABLE), "/usr/bin/firefox"),
185185
(BrowserPath::new(LINUX, BETA), "/usr/bin/firefox"),

rust/src/grid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl SeleniumManager for GridManager {
107107

108108
fn request_driver_version(&mut self) -> Result<String, Error> {
109109
let major_browser_version_binding = self.get_major_browser_version();
110-
let major_browser_version = major_browser_version_binding.as_str();
110+
let major_browser_version = &major_browser_version_binding.as_str();
111111
let cache_path = self.get_cache_path()?;
112112
let mut metadata = get_metadata(self.get_logger(), &cache_path);
113113

rust/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ pub const DEV: &str = "dev";
7474
pub const CANARY: &str = "canary";
7575
pub const NIGHTLY: &str = "nightly";
7676
pub const ESR: &str = "esr";
77-
pub const WMIC_COMMAND: &str = r#"wmic datafile where name='{}' get Version /value"#;
78-
pub const WMIC_COMMAND_OS: &str = r#"wmic os get osarchitecture"#;
77+
pub const WMIC_COMMAND: &str = "wmic datafile where name='{}' get Version /value";
78+
pub const WMIC_COMMAND_OS: &str = "wmic os get osarchitecture";
7979
pub const REG_VERSION_ARG: &str = "version";
8080
pub const REG_CURRENT_VERSION_ARG: &str = "CurrentVersion";
8181
pub const REG_PV_ARG: &str = "pv";
@@ -88,7 +88,7 @@ pub const MSIEXEC_INSTALL_COMMAND: &str = "start /wait msiexec /i {} /qn ALLOWDO
8888
pub const WINDOWS_CHECK_ADMIN_COMMAND: &str = "net session";
8989
pub const DASH_VERSION: &str = "{}{}{} -v";
9090
pub const DASH_DASH_VERSION: &str = "{}{}{} --version";
91-
pub const DOUBLE_QUOTE: &str = "\"";
91+
pub const DOUBLE_QUOTE: &str = r#"""#;
9292
pub const SINGLE_QUOTE: &str = "'";
9393
pub const ENV_PROGRAM_FILES: &str = "PROGRAMFILES";
9494
pub const ENV_PROGRAM_FILES_X86: &str = "PROGRAMFILES(X86)";
@@ -100,7 +100,7 @@ pub const ARCH_ARM64: &str = "arm64";
100100
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
101101
pub const TTL_SEC: u64 = 3600;
102102
pub const UNAME_COMMAND: &str = "uname -{}";
103-
pub const ESCAPE_COMMAND: &str = "printf %q \"{}\"";
103+
pub const ESCAPE_COMMAND: &str = r#"printf %q "{}""#;
104104
pub const SNAPSHOT: &str = "SNAPSHOT";
105105
pub const OFFLINE_REQUEST_ERR_MSG: &str = "Unable to discover proper {} version in offline mode";
106106
pub const OFFLINE_DOWNLOAD_ERR_MSG: &str = "Unable to download {} in offline mode";
@@ -484,7 +484,7 @@ pub trait SeleniumManager {
484484
}
485485
if self.is_webview2() && PathBuf::from(self.get_browser_path()).is_dir() {
486486
let browser_path = format!(
487-
r#"{}\{}\msedge{}"#,
487+
r"{}\{}\msedge{}",
488488
self.get_browser_path(),
489489
&self.get_browser_version(),
490490
get_binary_extension(self.get_os())
@@ -615,7 +615,7 @@ pub trait SeleniumManager {
615615
if WINDOWS.is(os) {
616616
let command = Command::new_single(WINDOWS_CHECK_ADMIN_COMMAND.to_string());
617617
let output = run_shell_command_by_os(os, command).unwrap_or_default();
618-
!output.is_empty() && !output.contains("error")
618+
!output.is_empty() && !output.contains("error") && !output.contains("not recognized")
619619
} else {
620620
false
621621
}
@@ -1061,16 +1061,14 @@ pub trait SeleniumManager {
10611061
cmd_version_arg: &str,
10621062
) -> Result<Option<String>, Error> {
10631063
let mut browser_path = self.get_browser_path().to_string();
1064-
let mut escaped_browser_path = self.get_escaped_path(browser_path.to_string());
10651064
if browser_path.is_empty() {
10661065
if let Some(path) = self.detect_browser_path() {
10671066
browser_path = path_to_string(&path);
1068-
escaped_browser_path = self.get_escaped_path(browser_path.to_string());
10691067
}
10701068
}
1069+
let escaped_browser_path = self.get_escaped_path(browser_path.to_string());
10711070

10721071
let mut commands = Vec::new();
1073-
10741072
if WINDOWS.is(self.get_os()) {
10751073
if !escaped_browser_path.is_empty() {
10761074
let wmic_command =

rust/src/safari.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use std::sync::mpsc::{Receiver, Sender};
3030

3131
pub const SAFARI_NAME: &str = "safari";
3232
pub const SAFARIDRIVER_NAME: &str = "safaridriver";
33-
const SAFARI_PATH: &str = r#"/Applications/Safari.app"#;
34-
const SAFARI_FULL_PATH: &str = r#"/Applications/Safari.app/Contents/MacOS/Safari"#;
33+
const SAFARI_PATH: &str = "/Applications/Safari.app";
34+
const SAFARI_FULL_PATH: &str = "/Applications/Safari.app/Contents/MacOS/Safari";
3535

3636
pub struct SafariManager {
3737
pub browser_name: &'static str,

rust/src/safaritp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pub const SAFARITP_NAMES: &[&str] = &[
3535
"safaritechnologypreview",
3636
];
3737
pub const SAFARITPDRIVER_NAME: &str = "safaridriver";
38-
const SAFARITP_PATH: &str = r#"/Applications/Safari Technology Preview.app"#;
38+
const SAFARITP_PATH: &str = "/Applications/Safari Technology Preview.app";
3939
const SAFARITP_FULL_PATH: &str =
40-
r#"/Applications/Safari Technology Preview.app/Contents/MacOS/Safari Technology Preview"#;
40+
"/Applications/Safari Technology Preview.app/Contents/MacOS/Safari Technology Preview";
4141

4242
pub struct SafariTPManager {
4343
pub browser_name: &'static str,

rust/tests/browser_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn invalid_geckodriver_version_test() {
136136
#[case(
137137
"macos",
138138
"chrome",
139-
r#"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"#
139+
r"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
140140
)]
141141
fn browser_path_test(#[case] os: String, #[case] browser: String, #[case] browser_path: String) {
142142
if OS.eq(&os) {

0 commit comments

Comments
 (0)