From 08a80e5ba22ac457da60c526c1c06f73a83b123d Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 20 Feb 2010 12:05:12 +1300 Subject: [PATCH] specialized-arrays: generate slightly more efficient byte-array>T-array words --- .../specialized-arrays/specialized-arrays.factor | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/basis/specialized-arrays/specialized-arrays.factor b/basis/specialized-arrays/specialized-arrays.factor index d3db93e788..e2840b89dd 100644 --- a/basis/specialized-arrays/specialized-arrays.factor +++ b/basis/specialized-arrays/specialized-arrays.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2008, 2009 Slava Pestov. +! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data alien.parser assocs byte-arrays classes compiler.units functors kernel lexer @@ -19,6 +19,11 @@ ERROR: bad-byte-array-length byte-array type ; M: bad-byte-array-length summary drop "Byte array length doesn't divide type width" ; +ERROR: not-a-byte-array alien ; + +M: not-a-byte-array summary + drop "Not a byte array" ; + : (underlying) ( n c-type -- array ) heap-size * (byte-array) ; inline @@ -61,9 +66,11 @@ TUPLE: A [ \ T heap-size calloc ] keep ; inline : byte-array>A ( byte-array -- specialized-array ) - >c-ptr dup length \ T heap-size /mod 0 = - [ drop \ T bad-byte-array-length ] unless - ; inline + >c-ptr dup byte-array? [ + dup length \ T heap-size /mod 0 = + [ ] + [ drop \ T bad-byte-array-length ] if + ] [ not-a-byte-array ] if ; inline M: A clone [ underlying>> clone ] [ length>> ] bi ; inline