Skip to content

Commit

Permalink
Dispatch optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
BarAgent committed Feb 18, 2014
1 parent e3092bd commit 92d2d5d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion sources/dfmc/modeling/types.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ end method;

define abstract &class <limited-type> (<type>) end &class;

define &class <limited-collection-type> (<limited-type>)
define primary &class <limited-collection-type> (<limited-type>)
constant &slot limited-collection-class :: <class>,
required-init-keyword: class:;
constant &slot limited-collection-element-type :: <type>,
Expand Down
5 changes: 3 additions & 2 deletions sources/dylan/limited-vector.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ define method make
unless (size = 0)
check-type(fill, element-type);
end unless;
let instance = system-allocate-repeated-instance
(<simple-element-type-vector>, <element-type>, element-type, size, fill);
let instance :: <simple-element-type-vector>
= system-allocate-repeated-instance
(<simple-element-type-vector>, <element-type>, element-type, size, fill);
instance.element-type-fill := default-fill;
instance
end method;
Expand Down
31 changes: 23 additions & 8 deletions sources/dylan/string.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,18 @@ define macro limited-string-definer
#key fill = ?fill, size :: <integer> = 0,
element-type-fill: default-fill = ?fill)
=> (res :: "<limited-" ## ?name ## "-string>")
unless (size = 0)
check-type(fill, "<" ## ?name ## "-character>")
end unless;
let instance = system-allocate-repeated-instance
("<limited-" ## ?name ## "-string>", "<" ## ?name ## "-character>", unbound(), size, fill);
// The user is not obligated to provide a fill value of the right type
// if we won't be needing it, but the fill variable does have to be the
// right type for the compiler to optimize system-allocate-repeated-instance.
let fill :: "<" ## ?name ## "-character>"
= if (size = 0)
?fill
else
check-type(fill, "<" ## ?name ## "-character>")
end;
let instance :: "<limited-" ## ?name ## "-string>"
= system-allocate-repeated-instance
("<limited-" ## ?name ## "-string>", "<" ## ?name ## "-character>", unbound(), size, fill);
instance.element-type-fill := default-fill;
instance
end method;
Expand Down Expand Up @@ -351,7 +358,11 @@ define macro string-definer
if (size = 0)
empty(class)
else
check-type(fill, "<" ## ?name ## "-character>");
// The user is not obligated to provide a fill value of the right type
// if we won't be needing it, but the fill variable does have to be the
// right type for the compiler to optimize system-allocate-repeated-instance.
let fill :: "<" ## ?name ## "-character>"
= check-type(fill, "<" ## ?name ## "-character>");
system-allocate-repeated-instance
("<" ## ?name ## "-string>", "<" ## ?name ## "-character>", unbound(), size, fill);
end if
Expand Down Expand Up @@ -428,12 +439,16 @@ end method;
define string-without-class byte (fill: ' ', class-name: byte);

define method make
(class == <byte-string>, #key fill = ' ', size :: <integer> = 0)
(class == <byte-string>, #key fill = as(<byte-character>, ' '),
size :: <integer> = 0)
=> (res :: <byte-string>)
if (size = 0)
empty(class)
else
check-type(fill, <byte-character>);
// The user is not obligated to provide a fill value of the right type
// if we won't be needing it, but the fill variable does have to be the
// right type for the compiler to optimize system-allocate-repeated-instance.
let fill :: <byte-character> = check-type(fill, <byte-character>);
system-allocate-repeated-instance
(<byte-string>, <byte-character>, unbound(), size, fill);
end if
Expand Down
17 changes: 12 additions & 5 deletions sources/dylan/vector.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,18 @@ define macro limited-vector-minus-selector-definer
#key fill = ?fill, size :: <integer> = 0,
element-type-fill: default-fill = ?fill)
=> (vector :: "<simple-" ## ?name ## "-vector>")
unless (size = 0)
check-type(fill, "<" ## ?name ## ">")
end unless;
let instance = system-allocate-repeated-instance
("<simple-" ## ?name ## "-vector>", "<" ## ?name ## ">", unbound(), size, fill);
// The user is not obligated to provide a fill value of the right type
// if we won't be needing it, but the fill variable does have to be the
// right type for the compiler to optimize system-allocate-repeated-instance.
let fill :: "<" ## ?name ## ">"
= if (size = 0)
?fill
else
check-type(fill, "<" ## ?name ## ">")
end;
let instance :: "<simple-" ## ?name ## "-vector>"
= system-allocate-repeated-instance
("<simple-" ## ?name ## "-vector>", "<" ## ?name ## ">", unbound(), size, fill);
instance.element-type-fill := default-fill;
instance
end method;
Expand Down

0 comments on commit 92d2d5d

Please sign in to comment.