Skip to content

Commit 34526b5

Browse files
jensensclaude
andcommitted
chore: clean up dead code and compiler warnings
Gate test-only functions with #[cfg(test)], prefix unused variables, and convert doc comments on macros to regular comments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3d6d709 commit 34526b5

8 files changed

Lines changed: 25 additions & 14 deletions

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 1.6.0 (unreleased)
44

5+
- Clean up dead code and compiler warnings: gate test-only functions with
6+
`#[cfg(test)]`, prefix unused variables, convert doc comments on macros
7+
to regular comments
8+
59
## 1.5.0 (2026-02-25)
610

711
- Direct PickleValue → JSON string writer (`json_writer.rs`), bypassing

src/json.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn pickle_value_to_json(val: &PickleValue) -> Result<Value, CodecError> {
1919
/// Like `pickle_value_to_json` but with PG-specific transformations:
2020
/// - Null-byte sanitization: strings containing `\0` → `{"@ns": base64}`
2121
/// - Persistent ref compaction: `(oid_bytes, None)` → `{"@ref": "hex_oid"}`
22+
#[cfg(test)]
2223
pub fn pickle_value_to_json_pg(val: &PickleValue) -> Result<Value, CodecError> {
2324
pickle_value_to_json_impl(val, true, true, 0)
2425
}

src/json_writer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct JsonWriter {
99
}
1010

1111
impl JsonWriter {
12+
#[cfg(test)]
1213
pub fn new() -> Self {
1314
Self {
1415
buf: String::new(),
@@ -22,11 +23,13 @@ impl JsonWriter {
2223
}
2324

2425
/// Consume the writer and return the JSON string.
26+
#[cfg(test)]
2527
pub fn into_string(self) -> String {
2628
self.buf
2729
}
2830

2931
/// Borrow the inner buffer (for length checks, etc.).
32+
#[cfg(test)]
3033
#[inline]
3134
pub fn as_str(&self) -> &str {
3235
&self.buf

src/known_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn try_write_instance_typed(
9898
fn write_datetime(
9999
w: &mut JsonWriter,
100100
args: &PickleValue,
101-
write_val: &dyn Fn(&mut JsonWriter, &PickleValue) -> Result<(), CodecError>,
101+
_write_val: &dyn Fn(&mut JsonWriter, &PickleValue) -> Result<(), CodecError>,
102102
) -> Result<bool, CodecError> {
103103
let tuple_items = match args {
104104
PickleValue::Tuple(items) => items,

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn dict_to_pickle(py: Python<'_>, obj: &Bound<'_, PyDict>) -> PyResult<Py<PyByte
6161
#[pyfunction]
6262
fn decode_zodb_record(py: Python<'_>, data: &[u8]) -> PyResult<Py<PyAny>> {
6363
// Release GIL during pure-Rust pickle parsing
64-
let (class_val, state_val, module, name) = py.detach(|| {
64+
let (_class_val, state_val, module, name) = py.detach(|| {
6565
let (class_val, state_val) = decode_zodb_pickles(data).map_err(CodecError::from)?;
6666
let (module, name) = zodb::extract_class_info(&class_val);
6767
Ok::<_, PyErr>((class_val, state_val, module, name))
@@ -95,7 +95,7 @@ fn decode_zodb_record(py: Python<'_>, data: &[u8]) -> PyResult<Py<PyAny>> {
9595
fn decode_zodb_record_for_pg(py: Python<'_>, data: &[u8]) -> PyResult<Py<PyAny>> {
9696
// Release GIL during pure-Rust pickle parsing + ref extraction.
9797
// This allows other Python threads to run during the CPU-bound phase.
98-
let (class_val, state_val, module, name, refs) = py.detach(|| {
98+
let (_class_val, state_val, module, name, refs) = py.detach(|| {
9999
let (class_val, state_val) = decode_zodb_pickles(data).map_err(CodecError::from)?;
100100
let (module, name) = zodb::extract_class_info(&class_val);
101101
let mut refs = Vec::new();

src/opcodes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub const MEMOIZE: u8 = 0x94; // store top in memo (auto-incrementing key)
7676
pub const FRAME: u8 = 0x95; // framing for protocol 4+
7777

7878
// -- Protocol 5 --
79+
#[allow(dead_code)]
7980
pub const BYTEARRAY8: u8 = 0x96; // push bytearray
81+
#[allow(dead_code)]
8082
pub const NEXT_BUFFER: u8 = 0x97; // push next out-of-band buffer
83+
#[allow(dead_code)]
8184
pub const READONLY_BUFFER: u8 = 0x98; // make top-of-stack read-only

src/pyconv.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,20 +1780,17 @@ pub fn encode_pyobject_as_pickle(
17801780
Ok(buf)
17811781
}
17821782

1783-
/// Encode a ZODB record (class + state) directly to concatenated pickle bytes.
1784-
/// Writes both the class pickle and state pickle directly, skipping
1785-
/// all PickleValue intermediate allocations.
1786-
/// Thread-local reusable buffer for encode_zodb_record_direct.
1787-
/// Avoids repeated Vec allocation + growth across calls — the buffer
1788-
/// retains its capacity from previous calls, so subsequent encodes
1789-
/// skip the initial growth phase.
1783+
// Thread-local reusable buffer for encode_zodb_record_direct.
1784+
// Avoids repeated Vec allocation + growth across calls — the buffer
1785+
// retains its capacity from previous calls, so subsequent encodes
1786+
// skip the initial growth phase.
17901787
thread_local! {
17911788
static ENCODE_BUF: std::cell::RefCell<Vec<u8>> =
17921789
const { std::cell::RefCell::new(Vec::new()) };
1793-
/// Cache of class pickle bytes per (module, name) pair.
1794-
/// Uses Vec for linear search — with ~6 distinct classes in a typical
1795-
/// ZODB database, linear search is faster than hashing and avoids
1796-
/// allocating key strings on every lookup.
1790+
// Cache of class pickle bytes per (module, name) pair.
1791+
// Uses Vec for linear search — with ~6 distinct classes in a typical
1792+
// ZODB database, linear search is faster than hashing and avoids
1793+
// allocating key strings on every lookup.
17971794
static CLASS_PICKLE_CACHE: std::cell::RefCell<Vec<(String, String, Vec<u8>)>> =
17981795
const { std::cell::RefCell::new(Vec::new()) };
17991796
}

src/zodb.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(test)]
12
use crate::error::CodecError;
23
use crate::types::PickleValue;
34

@@ -20,6 +21,7 @@ use serde_json::{json, Value};
2021
///
2122
/// We need to find the boundary between the two pickles.
2223
/// The first pickle ends at its STOP opcode (0x2e = '.').
24+
#[cfg(test)]
2325
pub fn split_zodb_record(data: &[u8]) -> Result<(&[u8], &[u8]), CodecError> {
2426
// We need to properly walk the first pickle to find its STOP opcode.
2527
// Simple approach: scan for STOP, but STOP byte (0x2e) can appear inside
@@ -31,6 +33,7 @@ pub fn split_zodb_record(data: &[u8]) -> Result<(&[u8], &[u8]), CodecError> {
3133
/// Find the end (exclusive) of the first pickle in the data.
3234
/// This walks the pickle opcodes to correctly skip over string/bytes
3335
/// data that might contain the STOP byte.
36+
#[cfg(test)]
3437
fn find_pickle_end(data: &[u8]) -> Result<usize, CodecError> {
3538
use crate::opcodes::*;
3639
let mut pos = 0;

0 commit comments

Comments
 (0)