Added optimization for string-length and bytes-length.

This commit is contained in:
Vincent St-Amour 2010-07-19 17:58:38 -04:00
parent d6ce6e664f
commit 4e944f73ab
6 changed files with 53 additions and 12 deletions

View File

@ -0,0 +1,6 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
(string-length "eh")
(bytes-length #"eh")

View File

@ -0,0 +1,6 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
(unsafe-string-length "eh")
(unsafe-bytes-length #"eh")

View File

@ -0,0 +1,6 @@
#lang typed/scheme
(require racket/unsafe/ops)
(string-length "eh")
(bytes-length #"eh")

View File

@ -2,10 +2,13 @@
(require syntax/parse (require syntax/parse
syntax/id-table racket/dict syntax/id-table racket/dict
(for-template scheme/base scheme/flonum scheme/fixnum scheme/unsafe/ops racket/private/for) (for-template scheme/base
scheme/flonum scheme/fixnum scheme/unsafe/ops
racket/private/for)
"../utils/utils.rkt" "../utils/utils.rkt"
(types abbrev type-table utils subtype) (types abbrev type-table utils subtype)
(optimizer utils fixnum float inexact-complex vector pair sequence box struct dead-code)) (optimizer utils fixnum float inexact-complex vector string
pair sequence box struct dead-code))
(provide optimize-top) (provide optimize-top)
@ -22,6 +25,7 @@
(pattern e:float-opt-expr #:with opt #'e.opt) (pattern e:float-opt-expr #:with opt #'e.opt)
(pattern e:inexact-complex-opt-expr #:with opt #'e.opt) (pattern e:inexact-complex-opt-expr #:with opt #'e.opt)
(pattern e:vector-opt-expr #:with opt #'e.opt) (pattern e:vector-opt-expr #:with opt #'e.opt)
(pattern e:string-opt-expr #:with opt #'e.opt)
(pattern e:pair-opt-expr #:with opt #'e.opt) (pattern e:pair-opt-expr #:with opt #'e.opt)
(pattern e:sequence-opt-expr #:with opt #'e.opt) (pattern e:sequence-opt-expr #:with opt #'e.opt)
(pattern e:box-opt-expr #:with opt #'e.opt) (pattern e:box-opt-expr #:with opt #'e.opt)

View File

@ -7,7 +7,7 @@
"../utils/utils.rkt" "../utils/tc-utils.rkt" "../utils/utils.rkt" "../utils/tc-utils.rkt"
(rep type-rep) (rep type-rep)
(types abbrev type-table utils subtype) (types abbrev type-table utils subtype)
(optimizer utils)) (optimizer utils string))
(provide sequence-opt-expr) (provide sequence-opt-expr)
@ -29,15 +29,6 @@
[_ #f]) [_ #f])
#:with opt ((optimize) #'e))) #:with opt ((optimize) #'e)))
(define-syntax-class string-expr
(pattern e:expr
#:when (isoftype? #'e -String)
#:with opt ((optimize) #'e)))
(define-syntax-class bytes-expr
(pattern e:expr
#:when (isoftype? #'e -Bytes)
#:with opt ((optimize) #'e)))
(define-syntax-class sequence-opt-expr (define-syntax-class sequence-opt-expr
;; if we're iterating (with the for macros) over something we know is a list, ;; if we're iterating (with the for macros) over something we know is a list,
;; we can generate code that would be similar to if in-list had been used ;; we can generate code that would be similar to if in-list had been used

View File

@ -0,0 +1,28 @@
#lang scheme/base
(require syntax/parse
(for-template scheme/base scheme/flonum scheme/unsafe/ops)
"../utils/utils.rkt"
(types abbrev type-table utils subtype)
(optimizer utils))
(provide string-opt-expr string-expr bytes-expr)
(define-syntax-class string-expr
(pattern e:expr
#:when (isoftype? #'e -String)
#:with opt ((optimize) #'e)))
(define-syntax-class bytes-expr
(pattern e:expr
#:when (isoftype? #'e -Bytes)
#:with opt ((optimize) #'e)))
(define-syntax-class string-opt-expr
(pattern (#%plain-app (~literal string-length) s:string-expr)
#:with opt
(begin (log-optimization "string" #'op)
#'(unsafe-string-length s.opt)))
(pattern (#%plain-app (~literal bytes-length) s:bytes-expr)
#:with opt
(begin (log-optimization "bytes" #'op)
#'(unsafe-bytes-length s.opt))))