Added an optimization for vector-length of known-length vectors.
This commit is contained in:
parent
eb7fc7a965
commit
e52d63ee68
|
@ -0,0 +1,3 @@
|
||||||
|
(module known-vector-length typed/scheme #:optimize
|
||||||
|
(require racket/unsafe/ops)
|
||||||
|
(+ 2 (vector-length (ann (vector 1 2) (Vector Integer Integer)))))
|
|
@ -0,0 +1,3 @@
|
||||||
|
(module known-vector-length typed/scheme #:optimize
|
||||||
|
(require racket/unsafe/ops)
|
||||||
|
(+ 2 (begin (vector 1 2) 2)))
|
|
@ -231,6 +231,16 @@
|
||||||
(begin (log-optimization "unary pair" #'op)
|
(begin (log-optimization "unary pair" #'op)
|
||||||
#'(op.unsafe p.opt)))
|
#'(op.unsafe p.opt)))
|
||||||
|
|
||||||
|
;; vector-length of a known-length vector
|
||||||
|
(pattern (#%plain-app (~and op (~or (~literal vector-length)
|
||||||
|
(~literal unsafe-vector-length)
|
||||||
|
(~literal unsafe-vector*-length)))
|
||||||
|
v:vector-opt-expr)
|
||||||
|
#:with opt
|
||||||
|
(begin (log-optimization "known-length vector" #'op)
|
||||||
|
(match (type-of #'v)
|
||||||
|
[(tc-result1: (HeterogenousVector: es))
|
||||||
|
#`(begin v.opt #,(length es))]))) ; v may have side effects
|
||||||
;; we can optimize vector-length on all vectors.
|
;; we can optimize vector-length on all vectors.
|
||||||
;; since the program typechecked, we know the arg is a vector.
|
;; since the program typechecked, we know the arg is a vector.
|
||||||
;; we can optimize no matter what.
|
;; we can optimize no matter what.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user