From: Sam Roberts Date: 2003-05-07T13:06:31+09:00 Subject: Re: Suggestion: String#pack Quoteing austin@halostatue.ca, on Wed, May 07, 2003 at 05:59:02AM +0900: > On Tue, 6 May 2003 23:18:29 +0900, dblack@superlink.net wrote: > I'm finding that the code I'm working with has several cases where I > could use String#pack or Fixnum#pack because I'm having to do: > > [foo].pack(template) > > .. and it's in loops, so the minimal inefficiency in creating an > anonymous Array will add up over time. Why not pre-create the Array: packee = [] loop { packee[0] = foo packee.pack(template) } Then instead of creating the Array, you're just asigning to the first element, which should be reasonably speedy, one hopes! Would this not work? Sam > can profile at this point, so I can't *prove* that it's > inefficient.) > > I don't think that this is too "magic"; I think that having to > create an anonymous array feels wrong, personally. > > BTW, Brian, the inefficiency of creating an anonymous Array -- in a > loop -- is precisely why I want String#pack and Fixnum#pack (I don't > want a generic #pack); a Float#pack may be useful. > > I think that it could be possible to have these be named differently > (per Matz's suggestion); perhaps #encode? I donno. > > -austin > -- Austin Ziegler, austin@halostatue.ca on 2003.05.06 at 16:38:07 > >