Commit 1361c90
committed
refactor: use cfg_if and rustix in read_to_string_bypass_system_cache (#802)
## Summary
Refactors `read_to_string_bypass_system_cache` to use `cfg_if` for cleaner platform-specific code and replaces unsafe `libc::posix_fadvise` with safe `rustix::fs::fadvise` on Linux.
## Changes
- **Code structure**: Refactored to use `cfg_if!` macro for platform-specific implementations
- **Linux**: Replaced `unsafe { libc::posix_fadvise(...) }` with `rustix::fs::fadvise(...)`
- **macOS**: Unchanged (still uses `F_NOCACHE`)
- **Other platforms**: Unchanged (falls back to `read_to_string`)
## Benefits
- **Safer**: Eliminates unsafe block for `posix_fadvise` on Linux
- **Cleaner**: Consistent use of `cfg_if!` across `file_system.rs`
- **Same performance**: `rustix::fs::fadvise` is a safe wrapper around `posix_fadvise`
- **Better structure**: Matches the pattern used in `metadata` functions
## Testing
- All existing tests pass
- Clippy checks pass
- Code formatted1 parent 1380ac2 commit 1361c90
3 files changed
+38
-45
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | 100 | | |
104 | 101 | | |
105 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| 256 | + | |
256 | 257 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
267 | 263 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
280 | 267 | | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
292 | 276 | | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
301 | 298 | | |
302 | 299 | | |
303 | 300 | | |
| |||
0 commit comments