Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99710 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45623 invoked from network); 3 Jul 2017 15:43:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jul 2017 15:43:25 -0000 Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.223.175 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.223.175 mail-io0-f175.google.com Received: from [209.85.223.175] ([209.85.223.175:33306] helo=mail-io0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 98/73-15131-C166A595 for ; Mon, 03 Jul 2017 11:43:24 -0400 Received: by mail-io0-f175.google.com with SMTP id h64so58644484iod.0 for ; Mon, 03 Jul 2017 08:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=swqJFljFuFnv340XbPow8EhpnfyioqFqS6qM0we7Tq4=; b=Zg6PO5DnjChdb4nS/JKQxL9HgP+XVyLZZpzaGxnKreqxm1mPYAFhgkXNeqPe2QT/+f TBn02j0UqxezV7f1nl+3gSlhJ+2y7ODgpAdz3ghl1kqnJpms0ko7+wUDh1x09jDajSF6 cd1sgeLo/02HC+o76MY9MTjMtROxKvORXnpc6BrOS3rpMe5RPJBmgnXO5H3PGY3qd4S5 tDqdwLA4KbaOsZ6hNerHCI12nXYKdT260PKDkD7oUzXJ9h2+09X5sdenRcDC9tEMIg8y Su3oAnkY0qGRzSSlyyDE3d4Ik/Oh/Ov6BGj9n7RMYKeS9MevVR9dp405t3NpfBC8l6lF VdOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=swqJFljFuFnv340XbPow8EhpnfyioqFqS6qM0we7Tq4=; b=b8KaGLh6T+/dB6OzXVvOWylkfGT1sE3IjQby7oElTaEDhvktHvb/WmH9d5+6SbSQaL Z6wz4CoQD+/jzhpBUKeSK6CJw6BIYtvrYMSEWDf0q3AazlFHw8783pmdHcBKk3fPTUvQ rzCXTjD+kAwRxSoM1RLgV0Eg7ZNLUyJtoLyII/UTj3spF6jRh4IuWPyluvuEJYV6H7g6 dTNx0FhVB1jh5Jlvx/cVitOjLaImukVsnhI0wwQB9djv7uj99HEFWFs6SMNxiH7uPL+l YvNXvo/F9OFK2XGMxkddazz8Bk8gjNLI0NpslIv6YZE//V9LlHJeTMRuGikPr6vBMV3E Hczg== X-Gm-Message-State: AKS2vOxT8eZlhJuDTgJdILy0H4R4+h3JLeRAeCv5GijQi4S7RWS+jwCZ AqTVn7LTVSbIVmvp9vY= X-Received: by 10.107.199.198 with SMTP id x189mr34064032iof.14.1499096601752; Mon, 03 Jul 2017 08:43:21 -0700 (PDT) Received: from mail-it0-f43.google.com (mail-it0-f43.google.com. [209.85.214.43]) by smtp.googlemail.com with ESMTPSA id 131sm10209833itk.10.2017.07.03.08.43.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jul 2017 08:43:21 -0700 (PDT) Received: by mail-it0-f43.google.com with SMTP id m68so89672402ith.1 for ; Mon, 03 Jul 2017 08:43:21 -0700 (PDT) X-Received: by 10.36.214.7 with SMTP id o7mr9030414itg.53.1499096600992; Mon, 03 Jul 2017 08:43:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.246.71 with HTTP; Mon, 3 Jul 2017 08:43:00 -0700 (PDT) In-Reply-To: References: Date: Mon, 3 Jul 2017 17:43:00 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] "Reader" as alternative to Iterator From: andreas@dqxtech.net (Andreas Hennings) Thanks everyone so far for the replies! I think I need to do some "homework", and come back with benchmarks and provide real examples. I remember that the overhead did make a difference in performance, but I should back that up with real data. For now just some inline replies. On Mon, Jul 3, 2017 at 3:42 PM, Sara Golemon wrote: > On Sun, Jul 2, 2017 at 10:49 PM, Andreas Hennings wrote: >> (I wanted dedicated reader classes for different return types, e.g. >> one "RowReader", one "AssocReader", one "ObjectReader". So here I >> would need one adapter class per type. But let's focus on the simple >> case, where you can use the same reader class.) >> > You need that anyway. If the current iterator returns one type and > you want to transform that into another type, then you need something > to actually do that. Having a reader interface won't magically know > that you want to change the output type. > > If I'm misunderstanding that, and you're saying that the output type > of the original iterator is already different and you somehow need a > different proxy to blindly pass through the different type then... No. > You don't. A single reader adapter will handle whatever type you pass > through it. Yes, the adapters were just blind proxies. In my own library I had dedicated reader types like XmlElementReaderInterface, RowReaderInterface (e.g. for CSV), AssocReaderInterface, ObjectReaderInterface, each with their own ->read() methods like ->getElement(), ->getRow(), ->getAssoc(), ->getObject(). So I ended up writing a distinct iterator adapter for each reader type. The different interfaces were helpful to prevent using a reader of the wrong type. But we would lose this anyway if this was implemented in core. All the methods would all collapse into just one method ->read(). Maybe some PhpDoc magic could help the IDE to distinguish the reader type. Currently my IDE does not support such a thing.