Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 7505: Improve the efficiency of copy-bytes.

* gwydion/d2c/runtime/dylan/buffer.dylan
  (copy-bytes methods): Seal and make inlineable.

* gwydion/common/common-dylan/byte-vector.dylan
  (copy-bytes methods): Supply specific methods for combinations of
   <byte-vector> and <byte-string>, implemented using the (inlineable)
   methods of copy-bytes in the System module of the Dylan library.
  • Loading branch information...
commit 21877045e4432b9a725370b408b6bb0596ac5c17 1 parent 738cd8b
@housel housel authored
View
54 common/common-dylan/byte-vector.dylan
@@ -108,6 +108,58 @@ define function copy-bytes-range-error
end function;
define sealed method copy-bytes
+ (dst :: <byte-vector>, dst-start :: <integer>,
+ src :: <byte-vector>, src-start :: <integer>, n :: <integer>) => ()
+ let src-end :: <integer> = src-start + n;
+ let dst-end :: <integer> = dst-start + n;
+ if (n >= 0 & src-start >= 0 & dst-start >= 0
+ & src-end <= size(src) & dst-end <= size(dst))
+ %copy-bytes(dst, dst-start, src, src-start, n);
+ else
+ copy-bytes-range-error(src, src-start, dst, dst-start, n);
+ end if;
+end method;
+
+define sealed method copy-bytes
+ (dst :: <byte-string>, dst-start :: <integer>,
+ src :: <byte-vector>, src-start :: <integer>, n :: <integer>) => ()
+ let src-end :: <integer> = src-start + n;
+ let dst-end :: <integer> = dst-start + n;
+ if (n >= 0 & src-start >= 0 & dst-start >= 0
+ & src-end <= size(src) & dst-end <= size(dst))
+ %copy-bytes(dst, dst-start, src, src-start, n);
+ else
+ copy-bytes-range-error(src, src-start, dst, dst-start, n);
+ end if;
+end method;
+
+define sealed method copy-bytes
+ (dst :: <byte-vector>, dst-start :: <integer>,
+ src :: <byte-string>, src-start :: <integer>, n :: <integer>) => ()
+ let src-end :: <integer> = src-start + n;
+ let dst-end :: <integer> = dst-start + n;
+ if (n >= 0 & src-start >= 0 & dst-start >= 0
+ & src-end <= size(src) & dst-end <= size(dst))
+ %copy-bytes(dst, dst-start, src, src-start, n);
+ else
+ copy-bytes-range-error(src, src-start, dst, dst-start, n);
+ end if;
+end method;
+
+define sealed method copy-bytes
+ (dst :: <byte-string>, dst-start :: <integer>,
+ src :: <byte-string>, src-start :: <integer>, n :: <integer>) => ()
+ let src-end :: <integer> = src-start + n;
+ let dst-end :: <integer> = dst-start + n;
+ if (n >= 0 & src-start >= 0 & dst-start >= 0
+ & src-end <= size(src) & dst-end <= size(dst))
+ %copy-bytes(dst, dst-start, src, src-start, n);
+ else
+ copy-bytes-range-error(src, src-start, dst, dst-start, n);
+ end if;
+end method;
+
+define sealed method copy-bytes
(dst :: <byte-vector>, dst-start :: <integer>,
src :: <simple-object-vector>, src-start :: <integer>, n :: <integer>) => ()
let src-end :: <integer> = src-start + n;
@@ -136,5 +188,3 @@ define sealed method copy-bytes
copy-bytes-range-error(src, src-start, dst, dst-start, n);
end if;
end method;
-
-// eof
View
15 d2c/runtime/dylan/buffer.dylan
@@ -87,50 +87,55 @@ define /* exported */ generic copy-bytes
// that the vector-elements works. Also, the mixed type operations can use
// memcpy, since the source and destination can't overlap.
-define method copy-bytes
+define sealed inline method copy-bytes
(dest :: <byte-vector>, dstart :: <integer>,
src :: <byte-vector>, sstart :: <integer>, count :: <integer>)
=> ();
+ c-include("string.h");
call-out("memmove", void:,
ptr: %%primitive(vector-elements, dest) + dstart,
ptr: %%primitive(vector-elements, src) + sstart,
int: count);
end method;
-define method copy-bytes
+define sealed inline method copy-bytes
(dest :: <byte-string>, dstart :: <integer>,
src :: <byte-vector>, sstart :: <integer>, count :: <integer>)
=> ();
+ c-include("string.h");
call-out("memcpy", void:,
ptr: %%primitive(vector-elements, dest) + dstart,
ptr: %%primitive(vector-elements, src) + sstart,
int: count);
end method;
-define method copy-bytes
+define sealed inline method copy-bytes
(dest :: <byte-vector>, dstart :: <integer>,
src :: <byte-string>, sstart :: <integer>, count :: <integer>)
=> ();
+ c-include("string.h");
call-out("memcpy", void:,
ptr: %%primitive(vector-elements, dest) + dstart,
ptr: %%primitive(vector-elements, src) + sstart,
int: count);
end method;
-define method copy-bytes
+define sealed inline method copy-bytes
(dest :: <byte-string>, dstart :: <integer>,
src :: <byte-string>, sstart :: <integer>, count :: <integer>)
=> ();
+ c-include("string.h");
call-out("memmove", void:,
ptr: %%primitive(vector-elements, dest) + dstart,
ptr: %%primitive(vector-elements, src) + sstart,
int: count);
end method;
-define method copy-bytes
+define sealed inline method copy-bytes
(dest :: <unicode-string>, dstart :: <integer>,
src :: <unicode-string>, sstart :: <integer>, count :: <integer>)
=> ();
+ c-include("string.h");
call-out("memmove", void:,
ptr: %%primitive(vector-elements, dest) + (2 * dstart),
ptr: %%primitive(vector-elements, src) + (2 * sstart),
Please sign in to comment.
Something went wrong with that request. Please try again.