Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73963 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50353 invoked from network); 6 May 2014 10:49:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2014 10:49:30 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.51 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.192.51 mail-qg0-f51.google.com Received: from [209.85.192.51] ([209.85.192.51:55614] helo=mail-qg0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/F6-04569-73EB8635 for ; Tue, 06 May 2014 06:49:27 -0400 Received: by mail-qg0-f51.google.com with SMTP id q107so4579882qgd.38 for ; Tue, 06 May 2014 03:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=hkE06/VmCa5whe5CGM1xiggaj6T2wEC2wPlxrycnZeQ=; b=uDiHPsUFmi5zHNeJ//67h4823vti3yrZYUUZV98t1i3H410kZ39WA8QroozVpREq6T KKAce59NqYBuBV4KvigOJblDqini9sUZ1YcQI22iZ1cModq1BbrulMgxlhyzAqZ8dY3r /z30U6gxMNJDzUp6JDg/TjNYsgBSICCIxIpb6b0AetlnHMEXlUxE43SIPC8mDniBLpBQ US8L9wNcj21grfnW/ubuo3s/23jR+WMNkbhsJHvlIT1z6jvqz/NavM8iAkRcA1eJUXHY TFdf8YZ86cnup/J+k9+Idrz3w/yHQUM9vUxRamVT2keqOjjZIsSuHshnyNbsZ3n+/2xe an1Q== MIME-Version: 1.0 X-Received: by 10.224.4.5 with SMTP id 5mr53096513qap.85.1399373364913; Tue, 06 May 2014 03:49:24 -0700 (PDT) Received: by 10.140.17.34 with HTTP; Tue, 6 May 2014 03:49:24 -0700 (PDT) In-Reply-To: References: Date: Tue, 6 May 2014 12:49:24 +0200 Message-ID: To: Aaron Lewis Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c219ea52eae604f8b900aa Subject: Re: [PHP-DEV] Looking for an example of zend_hash_quick_add() or zend_hash_add() From: tyra3l@gmail.com (Ferenc Kovacs) --001a11c219ea52eae604f8b900aa Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, May 5, 2014 at 11:29 AM, Aaron Lewis wr= ote: > Yes I can find examples in existing source code, > > zend_hash_quick_add(EG(active_symbol_table), key->arKey, > key->nKeyLength, key->h, &tmp, sizeof(zval*), (void**)&p); > > But I only know the HashTable, key, key length parameters, I'm not > sure what to fill in for the rest > > Can anyone give me an example? > > -- > Best Regards, > Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/ > Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > hi, http://lxr.php.net/xref/PHP_5_6/Zend/zend_hash.h#114 http://lxr.php.net/xref/PHP_5_6/Zend/zend_hash.c#308 #define zend_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) ht is the HashTable arKey is the key/index nKeyLength is the length of the key h is hash of the key pData is a pointer to the data nDataSize is the size of the data eg sizeof(zval *) pDest is the destination pointer, usually NULL because we don't care about it most of the times some docs on the hashtables: http://www.php.net/manual/en/internals2.variables.tables.php http://nikic.github.io/2012/03/28/Understanding-PHPs-internal-array-impleme= ntation.html http://www.phpinternalsbook.com/hashtables.html ( http://www.phpinternalsbook.com/hashtables/basic_structure.html is a good start) (and in Sara's book, Extending and Embedding PHP). and a simple example: http://www.phpinternalsbook.com/hashtables/hashtable_api.html#string-keys For all of the above functions there exists a second quick variant that > accepts a precomputed hash value after the string length. This allows you > to compute the hash of a string once and then reuse it across multiple > calls: > ulong h; /* hash value */ > /* ... zval init */ > h =3D zend_get_hash_value("foo", sizeof("foo")); > zend_hash_quick_update(myht, "foo", sizeof("foo"), h, &zv, sizeof(zval *)= , > NULL); > if (zend_hash_quick_find(myht, "foo", sizeof("foo"), h, (void **) > &zv_dest) =3D=3D SUCCESS) { > php_printf("Fetched value at key \"foo\" into zv_dest\n"); > } > if (zend_hash_quick_del(myht, "foo", sizeof("foo"), h) =3D=3D SUCCESS) { > php_printf("Removed value at key \"foo\"\n"); > } > Using the quick API improves performance as the hash value does not have > to be recomputed on every call. It should be noted though that this only > becomes significant if you are accessing the key a lot (e.g. in a loop). > The quick functions are mostly used in the engine where precomputed hash > values are available through various caches and optimizations. ps: somebody please correct me if I'm wrong somewhere! --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --001a11c219ea52eae604f8b900aa--