]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/trans/datum.rs
introduce `base_and_len` fns for element length
[rust.git] / src / librustc / middle / trans / datum.rs
index 34f1a6fa2a78a1507f1adb7d5213026b17dedd76..6411283b79d0e089a740723977fc27c8c43f21df 100644 (file)
@@ -794,6 +794,30 @@ pub fn get_vec_base_and_byte_len_no_root(&self, bcx: @mut Block)
         tvec::get_base_and_byte_len(bcx, llval, self.ty)
     }
 
+    pub fn get_vec_base_and_len(&self,
+                                     mut bcx: @mut Block,
+                                     span: Span,
+                                     expr_id: ast::NodeId,
+                                     derefs: uint)
+                                     -> (@mut Block, ValueRef, ValueRef) {
+        //! Converts a vector into the slice pair. Performs rooting
+        //! and write guards checks.
+
+        // only imp't for @[] and @str, but harmless
+        bcx = write_guard::root_and_write_guard(self, bcx, span, expr_id, derefs);
+        let (base, len) = self.get_vec_base_and_len_no_root(bcx);
+        (bcx, base, len)
+    }
+
+    pub fn get_vec_base_and_len_no_root(&self, bcx: @mut Block)
+                                             -> (ValueRef, ValueRef) {
+        //! Converts a vector into the slice pair. Des not root
+        //! nor perform write guard checks.
+
+        let llval = self.to_appropriate_llval(bcx);
+        tvec::get_base_and_len(bcx, llval, self.ty)
+    }
+
     pub fn root_and_write_guard(&self,
                                 bcx: @mut Block,
                                 span: Span,