Multiply entities beyond necessity even more (force better build parallelism)
[hiphop-php.git] / hphp / hack / src / parser / indexed_source_text.rs
blob4dfb3bfcba7d7adcea8f4819669257ed5e645a84
1 // Copyright (c) 2019, Facebook, Inc.
2 // All rights reserved.
3 //
4 // This source code is licensed under the MIT license found in the
5 // LICENSE file in the "hack" directory of this source tree.
7 use crate::source_text::SourceText;
8 use line_break_map::LineBreakMap;
9 use oxidized::pos::Pos;
11 #[derive(Debug)]
12 pub struct IndexedSourceText<'a> {
13     pub source_text: &'a SourceText<'a>,
14     offset_map: LineBreakMap,
17 impl<'a> IndexedSourceText<'a> {
18     pub fn new(source_text: &'a SourceText<'a>) -> Self {
19         IndexedSourceText {
20             source_text,
21             offset_map: LineBreakMap::new(source_text.text()),
22         }
23     }
25     pub fn source_text(&self) -> &SourceText {
26         self.source_text
27     }
29     pub fn offset_to_position(&self, offset: isize) -> (isize, isize) {
30         self.offset_map.offset_to_position(offset)
31     }
33     pub fn relative_pos(&self, start_offset: usize, end_offset: usize) -> Pos {
34         let pos_start = self.offset_map.offset_to_file_pos_triple(start_offset);
35         let pos_end = self.offset_map.offset_to_file_pos_triple(end_offset);
36         Pos::from_lnum_bol_cnum(self.source_text.file_path().clone(), pos_start, pos_end)
37     }