summary refs log tree commit diff stats
path: root/lib/system.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system.nim')
-rwxr-xr-xlib/system.nim23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/system.nim b/lib/system.nim
index bf9250a81..6eb6b3996 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -145,12 +145,14 @@ proc contains*[T](s: TSlice[T], value: T): bool {.noSideEffect, inline.} =
 when not defined(EcmaScript) and not defined(NimrodVM):
   type
     TGenericSeq {.compilerproc, pure.} = object
-      len, space: int
+      len, reserved: int
     PGenericSeq {.exportc.} = ptr TGenericSeq
     # len and space without counting the terminating zero:
     NimStringDesc {.compilerproc, final.} = object of TGenericSeq
       data: array[0..100_000_000, char]
     NimString = ptr NimStringDesc
+    
+  template space(s: PGenericSeq): int = s.reserved and not seqShallowFlag
 
   include "system/hti"
 
@@ -775,6 +777,8 @@ const
     ## a string that describes the application type. Possible values:
     ## "console", "gui", "lib".
   
+  seqShallowFlag = 1 shl (sizeof(int)*8-1)
+  
 proc compileOption*(option: string): bool {.
   magic: "CompileOption", noSideEffect.}
   ## can be used to determine an on|off compile-time option. Example:
@@ -2185,6 +2189,23 @@ template doAssert*(cond: expr, msg = "") =
       raiseAssert(astToStr(cond) & ' ' & msg)
 
 
+proc shallow*[T](s: seq[T]) {.noSideEffect, inline.} =
+  ## marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
+  ## perform deep copies of `s`. This is only useful for optimization 
+  ## purposes.
+  when not defined(EcmaScript) and not defined(NimrodVM):
+    var s = cast[PGenericSeq](s)
+    s.reserved = s.reserved or seqShallowFlag
+
+proc shallow*(s: string) {.noSideEffect, inline.} =
+  ## marks a string `s` as `shallow`:idx:. Subsequent assignments will not
+  ## perform deep copies of `s`. This is only useful for optimization 
+  ## purposes.
+  when not defined(EcmaScript) and not defined(NimrodVM):
+    var s = cast[PGenericSeq](s)
+    s.reserved = s.reserved or seqShallowFlag
+
+
 when defined(initDebugger):
   initDebugger()