@@ -47,8 +47,8 @@ impl std::fmt::Display for ProvenanceTableRow {
47
47
fn make_provenance_row ( table : & ProvenanceTable , pos : tsk_id_t ) -> Option < ProvenanceTableRow > {
48
48
Some ( ProvenanceTableRow {
49
49
id : pos. into ( ) ,
50
- timestamp : table. timestamp ( pos) ?,
51
- record : table. record ( pos) ?,
50
+ timestamp : table. timestamp ( pos) ?. to_string ( ) ,
51
+ record : table. record ( pos) ?. to_string ( ) ,
52
52
} )
53
53
}
54
54
@@ -122,35 +122,10 @@ impl<'a> streaming_iterator::StreamingIterator for ProvenanceTableRowView<'a> {
122
122
123
123
row_lending_iterator_get ! ( ) ;
124
124
125
- // FIXME: bad duplication
126
125
fn advance ( & mut self ) {
127
126
self . id = ( i32:: from ( self . id ) + 1 ) . into ( ) ;
128
- let record_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8 ! (
129
- self . id. 0 ,
130
- 0 ,
131
- self . table. num_rows( ) ,
132
- self . table. as_ref( ) ,
133
- record,
134
- record_offset,
135
- record_length
136
- ) ;
137
- self . record = match record_slice {
138
- Some ( r) => std:: str:: from_utf8 ( r) . unwrap ( ) ,
139
- None => "" ,
140
- } ;
141
- let timestamp_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8 ! (
142
- self . id. 0 ,
143
- 0 ,
144
- self . table. num_rows( ) ,
145
- self . table. as_ref( ) ,
146
- timestamp,
147
- timestamp_offset,
148
- timestamp_length
149
- ) ;
150
- self . timestamp = match timestamp_slice {
151
- Some ( t) => std:: str:: from_utf8 ( t) . unwrap ( ) ,
152
- None => "" ,
153
- } ;
127
+ self . record = self . table . record ( self . id ) . unwrap_or ( "" ) ;
128
+ self . timestamp = self . table . timestamp ( self . id ) . unwrap_or ( "" ) ;
154
129
}
155
130
}
156
131
@@ -209,16 +184,20 @@ impl ProvenanceTable {
209
184
/// # panic!("Expected Some(timestamp)");
210
185
/// # }
211
186
/// ```
212
- pub fn timestamp < P : Into < ProvenanceId > + Copy > ( & self , row : P ) -> Option < String > {
213
- unsafe_tsk_ragged_char_column_access ! (
187
+ pub fn timestamp < P : Into < ProvenanceId > + Copy > ( & self , row : P ) -> Option < & str > {
188
+ let timestamp_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8 ! (
214
189
row. into( ) . 0 ,
215
190
0 ,
216
191
self . num_rows( ) ,
217
192
self . as_ref( ) ,
218
193
timestamp,
219
194
timestamp_offset,
220
195
timestamp_length
221
- )
196
+ ) ;
197
+ match timestamp_slice {
198
+ Some ( tstamp) => std:: str:: from_utf8 ( tstamp) . ok ( ) ,
199
+ None => None ,
200
+ }
222
201
}
223
202
224
203
/// Get the provenance record for row `row`.
@@ -241,16 +220,20 @@ impl ProvenanceTable {
241
220
/// # else {
242
221
/// # panic!("Expected Some(timestamp)");
243
222
/// # }
244
- pub fn record < P : Into < ProvenanceId > + Copy > ( & self , row : P ) -> Option < String > {
245
- unsafe_tsk_ragged_char_column_access ! (
223
+ pub fn record < P : Into < ProvenanceId > + Copy > ( & self , row : P ) -> Option < & str > {
224
+ let record_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8 ! (
246
225
row. into( ) . 0 ,
247
226
0 ,
248
227
self . num_rows( ) ,
249
228
self . as_ref( ) ,
250
229
record,
251
230
record_offset,
252
231
record_length
253
- )
232
+ ) ;
233
+ match record_slice {
234
+ Some ( rec) => std:: str:: from_utf8 ( rec) . ok ( ) ,
235
+ None => None ,
236
+ }
254
237
}
255
238
256
239
/// Obtain a [`ProvenanceTableRow`] for row `row`.
@@ -271,37 +254,12 @@ impl ProvenanceTable {
271
254
/// * `None` otherwise
272
255
pub fn row_view < P : Into < ProvenanceId > + Copy > ( & self , row : P ) -> Option < ProvenanceTableRowView > {
273
256
match u64:: try_from ( row. into ( ) . 0 ) . ok ( ) {
274
- // FIXME: bad duplication
275
257
Some ( x) if x < self . num_rows ( ) => {
276
- let record_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8 ! (
277
- row. into( ) . 0 ,
278
- 0 ,
279
- self . num_rows( ) ,
280
- self . as_ref( ) ,
281
- record,
282
- record_offset,
283
- record_length
284
- ) ;
285
- let timestamp_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8 ! (
286
- row. into( ) . 0 ,
287
- 0 ,
288
- self . num_rows( ) ,
289
- self . as_ref( ) ,
290
- timestamp,
291
- timestamp_offset,
292
- timestamp_length
293
- ) ;
294
258
let view = ProvenanceTableRowView {
295
259
table : self ,
296
260
id : row. into ( ) ,
297
- record : match record_slice {
298
- Some ( r) => std:: str:: from_utf8 ( r) . unwrap ( ) ,
299
- None => "" ,
300
- } ,
301
- timestamp : match timestamp_slice {
302
- Some ( t) => std:: str:: from_utf8 ( t) . unwrap ( ) ,
303
- None => "" ,
304
- } ,
261
+ record : self . record ( row) ?,
262
+ timestamp : self . timestamp ( row) ?,
305
263
} ;
306
264
Some ( view)
307
265
}
0 commit comments