Skip to content

Commit 6463394

Browse files
committed
use std::string_view for efficiency like Ffilesystem
1 parent 3e27775 commit 6463394

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

buildfile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function publishTask(context)
9696
srcs = {
9797
["src/is_admin.cpp", "src/admin_fs.cpp"] ...
9898
"src/is_char_device.cpp", ...
99-
["src/is_wsl.cpp", "src/linux_fs.cpp"], ...
99+
["src/is_wsl.cpp", linux], ...
100100
"src/set_permissions.cpp", ...
101101
["src/is_rosetta.cpp", mac], ...
102102
["src/windows_shortname.cpp", win], ...

src/is_char_device.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "mexAdapter.hpp"
1010

1111
#include <string>
12-
// note: <string_view> causes compile failures with MSVC at least
12+
#include <string_view>
1313

1414
#include <vector>
1515
#include <memory>
@@ -25,7 +25,7 @@
2525
#include <sys/types.h>
2626
#include <sys/stat.h>
2727

28-
static int fs_st_mode(std::string path)
28+
static int fs_st_mode(std::string_view path)
2929
{
3030
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions
3131
struct stat s;
@@ -34,7 +34,7 @@ static int fs_st_mode(std::string path)
3434
}
3535

3636

37-
static bool fs_is_char_device(std::string path)
37+
static bool fs_is_char_device(std::string_view path)
3838
{
3939
// character device like /dev/null or CONIN$
4040
#if defined(_MSC_VER)

src/set_permissions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "mexAdapter.hpp"
66

77
#include <string>
8+
#include <string_view>
89

910
#include <vector>
1011
#include <memory>
@@ -15,7 +16,7 @@
1516
#endif
1617

1718

18-
static bool fs_set_permissions(std::string path, int readable, int writable, int executable)
19+
static bool fs_set_permissions(std::string_view path, int readable, int writable, int executable)
1920
{
2021
#ifdef __cpp_lib_filesystem
2122

src/symlink_fs.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#endif
66

77
#include <string>
8+
#include <string_view>
89

910
#if __has_include(<filesystem>)
1011
# include <filesystem>
@@ -19,7 +20,7 @@
1920

2021

2122

22-
bool fs_create_symlink(std::string target, std::string link)
23+
bool fs_create_symlink(std::string_view target, std::string_view link)
2324
{
2425
// confusing program errors if target is "" -- we'd never make such a symlink in real use.
2526
if(target.empty())
@@ -64,7 +65,7 @@ bool fs_create_symlink(std::string target, std::string link)
6465
}
6566

6667

67-
bool fs_is_symlink(std::string path)
68+
bool fs_is_symlink(std::string_view path)
6869
{
6970

7071
#if defined(__MINGW32__) || (defined(_WIN32) && !defined(__cpp_lib_filesystem))
@@ -81,7 +82,7 @@ bool fs_is_symlink(std::string path)
8182
}
8283

8384

84-
std::string fs_read_symlink(std::string path)
85+
std::string fs_read_symlink(std::string_view path)
8586
{
8687

8788
if(!fs_is_symlink(path))

src/symlink_fs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <string>
2+
#include <string_view>
23

3-
bool fs_is_symlink(std::string);
4-
bool fs_create_symlink(std::string, std::string);
5-
std::string fs_read_symlink(std::string);
4+
bool fs_is_symlink(std::string_view);
5+
bool fs_create_symlink(std::string_view, std::string_view);
6+
std::string fs_read_symlink(std::string_view);

src/win32_fs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <string>
2+
#include <string_view>
23

3-
bool fs_win32_is_symlink(std::string);
4+
bool fs_win32_is_symlink(std::string_view);
45

5-
std::string fs_shortname(std::string);
6+
std::string fs_shortname(std::string_view);
67

7-
std::string fs_as_posix(std::string);
8+
std::string fs_as_posix(std::string_view);

src/windows.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef struct _REPARSE_DATA_BUFFER
5757
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
5858

5959

60-
std::string fs_as_posix(std::string path)
60+
std::string fs_as_posix(std::string_view path)
6161
{
6262
std::string s(path);
6363

@@ -69,7 +69,7 @@ std::string fs_as_posix(std::string path)
6969
}
7070

7171

72-
static bool fs_win32_get_reparse_buffer(std::string path, std::byte* buffer)
72+
static bool fs_win32_get_reparse_buffer(std::string_view path, std::byte* buffer)
7373
{
7474
// this function is adapted from
7575
// https://gitlab.kitware.com/utils/kwsys/-/blob/master/SystemTools.cxx
@@ -111,7 +111,7 @@ static bool fs_win32_get_reparse_buffer(std::string path, std::byte* buffer)
111111
}
112112

113113

114-
std::string fs_win32_final_path(std::string path)
114+
std::string fs_win32_final_path(std::string_view path)
115115
{
116116
// resolves Windows symbolic links (reparse points and junctions)
117117
// it also resolves the case insensitivity of Windows paths to the disk case
@@ -153,7 +153,7 @@ std::string fs_win32_final_path(std::string path)
153153
}
154154

155155

156-
bool fs_win32_is_symlink(std::string path)
156+
bool fs_win32_is_symlink(std::string_view path)
157157
{
158158
// distinguish between Windows symbolic links and reparse points as
159159
// reparse points can be unlike symlinks.
@@ -177,7 +177,7 @@ bool fs_win32_is_symlink(std::string path)
177177
}
178178

179179

180-
std::string fs_shortname(std::string in)
180+
std::string fs_shortname(std::string_view in)
181181
{
182182
// https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getshortpathnamew
183183
// the path must exist

0 commit comments

Comments
 (0)