aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-09 14:15:07 -0800
committerGraydon Hoare <[email protected]>2010-11-09 14:15:07 -0800
commit89946609f2de815ea87df3b001fff0caf9efa0d5 (patch)
tree0945861dddd480b822827d77205f90584d0c2586 /src/lib
parentAdd a check for binding an alias. Good thing, as we had two instances in our ... (diff)
downloadrust-89946609f2de815ea87df3b001fff0caf9efa0d5.tar.xz
rust-89946609f2de815ea87df3b001fff0caf9efa0d5.zip
Support a special const-value refcount, use it for const strings.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/_str.rs9
-rw-r--r--src/lib/_vec.rs9
-rw-r--r--src/lib/dbg.rs3
3 files changed, 17 insertions, 4 deletions
diff --git a/src/lib/_str.rs b/src/lib/_str.rs
index 0fc7b373..4ea5ca28 100644
--- a/src/lib/_str.rs
+++ b/src/lib/_str.rs
@@ -97,8 +97,13 @@ fn from_bytes(vec[u8] v) : is_utf8(v) -> str {
}
fn refcount(str s) -> uint {
- // -1 because calling this function incremented the refcount.
- ret rustrt.refcount[u8](s) - 1u;
+ auto r = rustrt.refcount[u8](s);
+ if (r == dbg.const_refcount) {
+ ret r;
+ } else {
+ // -1 because calling this function incremented the refcount.
+ ret r - 1u;
+ }
}
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs
index c2ca95fc..6fa0ed42 100644
--- a/src/lib/_vec.rs
+++ b/src/lib/_vec.rs
@@ -30,8 +30,13 @@ fn alloc[T](uint n_elts) -> vec[T] {
}
fn refcount[T](vec[T] v) -> uint {
- // -1 because calling this function incremented the refcount.
- ret rustrt.refcount[T](v) - 1u;
+ auto r = rustrt.refcount[T](v);
+ if (r == dbg.const_refcount) {
+ ret r;
+ } else {
+ // -1 because calling this function incremented the refcount.
+ ret r - 1u;
+ }
}
type init_op[T] = fn(uint i) -> T;
diff --git a/src/lib/dbg.rs b/src/lib/dbg.rs
index 6c856cf7..51a31e07 100644
--- a/src/lib/dbg.rs
+++ b/src/lib/dbg.rs
@@ -7,6 +7,9 @@
import std._vec;
+// FIXME: handle 64-bit case.
+const uint const_refcount = 0x7bad_face_u;
+
native "rust" mod rustrt {
fn debug_tydesc[T]();
fn debug_opaque[T](&T x);